OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 REMOTING_PROTOCOL_PAIRING_REGISTRY_DELEGATE_LINUX_H_ |
| 6 #define REMOTING_PROTOCOL_PAIRING_REGISTRY_DELEGATE_LINUX_H_ |
| 7 |
| 8 #include "remoting/protocol/pairing_registry.h" |
| 9 |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 |
| 13 namespace base { |
| 14 class ListValue; |
| 15 class TaskRunner; |
| 16 } // namespace base |
| 17 |
| 18 namespace remoting { |
| 19 |
| 20 class PairingRegistryDelegateLinux |
| 21 : public protocol::PairingRegistry::Delegate { |
| 22 public: |
| 23 explicit PairingRegistryDelegateLinux( |
| 24 scoped_refptr<base::TaskRunner> task_runner); |
| 25 virtual ~PairingRegistryDelegateLinux(); |
| 26 |
| 27 // PairingRegistry::Delegate interface |
| 28 virtual void Save( |
| 29 const std::string& pairings_json, |
| 30 const protocol::PairingRegistry::SaveCallback& callback) OVERRIDE; |
| 31 virtual void Load( |
| 32 const protocol::PairingRegistry::LoadCallback& callback) OVERRIDE; |
| 33 |
| 34 private: |
| 35 FRIEND_TEST_ALL_PREFIXES(PairingRegistryDelegateLinuxTest, SaveAndLoad); |
| 36 |
| 37 // Blocking helper methods run using the TaskRunner passed to the ctor. |
| 38 void DoSave(const std::string& pairings_json, |
| 39 const protocol::PairingRegistry::SaveCallback& callback); |
| 40 void DoLoad(const protocol::PairingRegistry::LoadCallback& callback); |
| 41 |
| 42 // Run the delegate callbacks on their original thread. |
| 43 static void RunSaveCallbackOnThread( |
| 44 scoped_refptr<base::TaskRunner> task_runner, |
| 45 const protocol::PairingRegistry::SaveCallback& callback, |
| 46 bool success); |
| 47 static void RunLoadCallbackOnThread( |
| 48 scoped_refptr<base::TaskRunner> task_runner, |
| 49 const protocol::PairingRegistry::LoadCallback& callback, |
| 50 const std::string& pairings_json); |
| 51 |
| 52 // Helper methods to load and save the pairing registry. |
| 53 protocol::PairingRegistry::PairedClients LoadPairings(); |
| 54 void SavePairings( |
| 55 const protocol::PairingRegistry::PairedClients& paired_clients); |
| 56 |
| 57 // Return the path to the file to use for loading and saving paired clients. |
| 58 base::FilePath GetRegistryFilePath(); |
| 59 |
| 60 // For testing purposes, set the path returned by |GetRegistryFilePath|. |
| 61 void SetFilenameForTesting(const base::FilePath &filename); |
| 62 |
| 63 scoped_refptr<base::TaskRunner> task_runner_; |
| 64 base::FilePath filename_for_testing_; |
| 65 |
| 66 base::WeakPtrFactory<PairingRegistryDelegateLinux> weak_factory_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(PairingRegistryDelegateLinux); |
| 69 }; |
| 70 |
| 71 } // namespace remoting |
| 72 |
| 73 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_DELEGATE_LINUX_H_ |
OLD | NEW |