OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_PROTOCOL_PAIRING_REGISTRY_DELEGATE_LINUX_H_ | 5 #ifndef REMOTING_PROTOCOL_PAIRING_REGISTRY_DELEGATE_LINUX_H_ |
6 #define REMOTING_PROTOCOL_PAIRING_REGISTRY_DELEGATE_LINUX_H_ | 6 #define REMOTING_PROTOCOL_PAIRING_REGISTRY_DELEGATE_LINUX_H_ |
7 | 7 |
8 #include "remoting/protocol/pairing_registry.h" | 8 #include "remoting/protocol/pairing_registry.h" |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/memory/weak_ptr.h" | |
12 | 11 |
13 namespace base { | 12 namespace base { |
14 class ListValue; | 13 class ListValue; |
15 class TaskRunner; | |
16 } // namespace base | 14 } // namespace base |
17 | 15 |
18 namespace remoting { | 16 namespace remoting { |
19 | 17 |
20 class PairingRegistryDelegateLinux | 18 class PairingRegistryDelegateLinux |
21 : public protocol::PairingRegistry::Delegate { | 19 : public protocol::PairingRegistry::Delegate { |
22 public: | 20 public: |
23 explicit PairingRegistryDelegateLinux( | 21 PairingRegistryDelegateLinux(); |
24 scoped_refptr<base::TaskRunner> task_runner); | |
25 virtual ~PairingRegistryDelegateLinux(); | 22 virtual ~PairingRegistryDelegateLinux(); |
26 | 23 |
27 // PairingRegistry::Delegate interface | 24 // PairingRegistry::Delegate interface |
28 virtual void Save( | 25 virtual scoped_ptr<base::ListValue> LoadAll() OVERRIDE; |
29 const std::string& pairings_json, | 26 virtual bool DeleteAll() OVERRIDE; |
30 const protocol::PairingRegistry::SaveCallback& callback) OVERRIDE; | 27 virtual protocol::PairingRegistry::Pairing Load( |
31 virtual void Load( | 28 const std::string& client_id) OVERRIDE; |
32 const protocol::PairingRegistry::LoadCallback& callback) OVERRIDE; | 29 virtual bool Save(const protocol::PairingRegistry::Pairing& pairing) OVERRIDE; |
| 30 virtual bool Delete(const std::string& client_id) OVERRIDE; |
33 | 31 |
34 private: | 32 private: |
| 33 FRIEND_TEST_ALL_PREFIXES(PairingRegistryDelegateLinuxTest, Empty); |
| 34 FRIEND_TEST_ALL_PREFIXES(PairingRegistryDelegateLinuxTest, Delete); |
35 FRIEND_TEST_ALL_PREFIXES(PairingRegistryDelegateLinuxTest, SaveAndLoad); | 35 FRIEND_TEST_ALL_PREFIXES(PairingRegistryDelegateLinuxTest, SaveAndLoad); |
36 | 36 |
37 // Blocking helper methods run using the TaskRunner passed to the ctor. | 37 // Return the path to the directory to use for loading and saving paired |
38 void DoSave(const std::string& pairings_json, | 38 // clients. |
39 const protocol::PairingRegistry::SaveCallback& callback); | 39 base::FilePath GetRegistryPath(); |
40 void DoLoad(const protocol::PairingRegistry::LoadCallback& callback); | |
41 | 40 |
42 // Run the delegate callbacks on their original thread. | 41 // For testing purposes, set the path returned by |GetRegistryPath()|. |
43 static void RunSaveCallbackOnThread( | 42 void SetRegistryPathForTesting(const base::FilePath& registry_path); |
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 | 43 |
52 // Helper methods to load and save the pairing registry. | 44 base::FilePath registry_path_for_testing_; |
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 | 45 |
68 DISALLOW_COPY_AND_ASSIGN(PairingRegistryDelegateLinux); | 46 DISALLOW_COPY_AND_ASSIGN(PairingRegistryDelegateLinux); |
69 }; | 47 }; |
70 | 48 |
71 } // namespace remoting | 49 } // namespace remoting |
72 | 50 |
73 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_DELEGATE_LINUX_H_ | 51 #endif // REMOTING_PROTOCOL_PAIRING_REGISTRY_DELEGATE_LINUX_H_ |
OLD | NEW |