Home | History | Annotate | Download | only in clipboard
      1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef MOJO_SERVICES_CLIPBOARD_CLIPBOARD_STANDALONE_IMPL_H_
      6 #define MOJO_SERVICES_CLIPBOARD_CLIPBOARD_STANDALONE_IMPL_H_
      7 
      8 #include <base/memory/scoped_ptr.h>
      9 #include <string>
     10 
     11 #include "mojo/services/public/interfaces/clipboard/clipboard.mojom.h"
     12 
     13 namespace mojo {
     14 
     15 // Stub clipboard implementation.
     16 //
     17 // Eventually, we'll actually want to interact with the system clipboard, but
     18 // that's hard today because the system clipboard is asynchronous (on X11), the
     19 // ui::Clipboard interface is synchronous (which is what we'd use), mojo is
     20 // asynchronous across processes, and the WebClipboard interface is synchronous
     21 // (which is at least tractable).
     22 class ClipboardStandaloneImpl : public InterfaceImpl<mojo::Clipboard> {
     23  public:
     24   // mojo::Clipboard exposes three possible clipboards.
     25   static const int kNumClipboards = 3;
     26 
     27   ClipboardStandaloneImpl();
     28   virtual ~ClipboardStandaloneImpl();
     29 
     30   // InterfaceImpl<mojo::Clipboard> implementation.
     31   virtual void GetSequenceNumber(Clipboard::Type clipboard_type,
     32                                  const mojo::Callback<void(uint64_t)>& callback)
     33       MOJO_OVERRIDE;
     34   virtual void GetAvailableMimeTypes(
     35       Clipboard::Type clipboard_types,
     36       const mojo::Callback<void(mojo::Array<mojo::String>)>& callback)
     37       MOJO_OVERRIDE;
     38   virtual void ReadMimeType(
     39       Clipboard::Type clipboard_type,
     40       const mojo::String& mime_type,
     41       const mojo::Callback<void(mojo::Array<uint8_t>)>& callback)
     42       MOJO_OVERRIDE;
     43   virtual void WriteClipboardData(Clipboard::Type clipboard_type,
     44                                   mojo::Array<MimeTypePairPtr> data)
     45       MOJO_OVERRIDE;
     46 
     47  private:
     48   uint64_t sequence_number_[kNumClipboards];
     49 
     50   // Internal struct which stores the current state of the clipboard.
     51   class ClipboardData;
     52 
     53   // The current clipboard state. This is what is read from.
     54   scoped_ptr<ClipboardData> clipboard_state_[kNumClipboards];
     55 
     56   DISALLOW_COPY_AND_ASSIGN(ClipboardStandaloneImpl);
     57 };
     58 
     59 }  // namespace mojo
     60 
     61 #endif  // MOJO_SERVICES_CLIPBOARD_CLIPBOARD_STANDALONE_IMPL_H_
     62