Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: chrome/browser/chromeos/login/signed_settings.h

Issue 8727037: Signed settings refactoring: Proper caching and more tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to ToT and removed some debug output left. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "chrome/browser/chromeos/login/owner_manager.h" 14 #include "chrome/browser/chromeos/login/owner_manager.h"
15 15
16 // There are two categories of operations that can be performed on the 16 // There are two operations that can be performed on the Chrome OS owner-signed
17 // Chrome OS owner-signed settings store: 17 // settings store: Storing and Retrieving the policy blob.
Mattias Nissler (ping if slow) 2011/11/30 11:22:44 Now that this is much simpler, is it still useful
pastarmovj 2011/11/30 17:21:16 Maybe if we rename the SignedSettingsHelper to Sig
18 // 1) doing stuff to the whitelist (adding/removing/checking)
19 // 2) Storing/Retrieving arbitrary name=value pairs
20 // 18 //
21 // Unfortunately, it is currently a limitation that only one of each
22 // category can be in-flight at a time. You can be doing exactly one thing
23 // to the whitelist, and exactly one thing to the property store at a time.
24 // I've filed an issue on me to remove that restriction.
25 // http://code.google.com/p/chromium-os/issues/detail?id=6415
26
27 // The pattern of use here is that the caller instantiates some 19 // The pattern of use here is that the caller instantiates some
28 // subclass of SignedSettings by calling one of the create 20 // subclass of SignedSettings by calling one of the create
29 // methods. Then, call Execute() on this object from the UI 21 // methods. Then, call Execute() on this object from the UI
30 // thread. It'll go off and do work (on the FILE thread and over DBus), 22 // thread. It'll go off and do work (on the FILE thread and over DBus),
31 // and then call the appropriate method of the Delegate you passed in 23 // and then call the appropriate method of the Delegate you passed in
32 // -- again, on the UI thread. 24 // -- again, on the UI thread.
33 25
34 namespace base { 26 namespace base {
35 class Value; 27 class Value;
36 } // namespace base 28 } // namespace base
37 29
38 namespace enterprise_management { 30 namespace enterprise_management {
39 class PolicyFetchResponse; 31 class PolicyFetchResponse;
40 class PolicyData; 32 class PolicyData;
41 } // namespace enterprise_management 33 } // namespace enterprise_management
42 namespace em = enterprise_management; 34 namespace em = enterprise_management;
43 35
44 namespace chromeos { 36 namespace chromeos {
45 class OwnershipService; 37 class OwnershipService;
46 38
39 extern const char kDevicePolicyType[];
40
47 class SignedSettings : public base::RefCountedThreadSafe<SignedSettings>, 41 class SignedSettings : public base::RefCountedThreadSafe<SignedSettings>,
48 public OwnerManager::Delegate { 42 public OwnerManager::Delegate {
49 public: 43 public:
50 enum ReturnCode { 44 enum ReturnCode {
51 SUCCESS, 45 SUCCESS,
52 NOT_FOUND, // Email address or property name not found. 46 NOT_FOUND, // Email address or property name not found.
53 KEY_UNAVAILABLE, // Owner key not yet configured. 47 KEY_UNAVAILABLE, // Owner key not yet configured.
54 OPERATION_FAILED, // IPC to signed settings daemon failed. 48 OPERATION_FAILED, // IPC to signed settings daemon failed.
55 BAD_SIGNATURE // Signature verification failed. 49 BAD_SIGNATURE // Signature verification failed.
56 }; 50 };
57 51
58 template <class T> 52 template <class T>
59 class Delegate { 53 class Delegate {
60 public: 54 public:
61 // This method will be called on the UI thread. 55 // This method will be called on the UI thread.
62 virtual void OnSettingsOpCompleted(ReturnCode code, T value) {} 56 virtual void OnSettingsOpCompleted(ReturnCode code, T value) {}
63 }; 57 };
64 58
65 SignedSettings(); 59 SignedSettings();
66 virtual ~SignedSettings(); 60 virtual ~SignedSettings();
67 61
68 // These are both "property" operations, and only one instance of
69 // one type can be in flight at a time.
70 static SignedSettings* CreateStorePropertyOp(
71 const std::string& name,
72 const base::Value& value,
73 SignedSettings::Delegate<bool>* d);
74
75 static SignedSettings* CreateRetrievePropertyOp(
76 const std::string& name,
77 SignedSettings::Delegate<const base::Value*>* d);
78
79 // These are both "policy" operations, and only one instance of 62 // These are both "policy" operations, and only one instance of
80 // one type can be in flight at a time. 63 // one type can be in flight at a time.
81 static SignedSettings* CreateStorePolicyOp( 64 static SignedSettings* CreateStorePolicyOp(
82 em::PolicyFetchResponse* policy, 65 em::PolicyFetchResponse* policy,
83 SignedSettings::Delegate<bool>* d); 66 SignedSettings::Delegate<bool>* d);
84 67
85 static SignedSettings* CreateRetrievePolicyOp( 68 static SignedSettings* CreateRetrievePolicyOp(
86 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d); 69 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d);
87 70
88 static ReturnCode MapKeyOpCode(OwnerManager::KeyOpCode code); 71 static ReturnCode MapKeyOpCode(OwnerManager::KeyOpCode code);
89 72
90 virtual void Execute() = 0; 73 virtual void Execute() = 0;
91 74
92 virtual void Fail(ReturnCode code) = 0; 75 virtual void Fail(ReturnCode code) = 0;
93 76
94 // Implementation of OwnerManager::Delegate 77 // Implementation of OwnerManager::Delegate
95 virtual void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, 78 virtual void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code,
96 const std::vector<uint8>& payload) = 0; 79 const std::vector<uint8>& payload) = 0;
97 80
98 protected: 81 protected:
99 static bool PolicyIsSane(const em::PolicyFetchResponse& value, 82 static bool PolicyIsSane(const em::PolicyFetchResponse& value,
100 em::PolicyData* poldata); 83 em::PolicyData* poldata);
101 84
102 void set_service(OwnershipService* service) { service_ = service; } 85 void set_service(OwnershipService* service) { service_ = service; }
103 86
104 void TryToFetchPolicyAndCallBack();
105
106 OwnershipService* service_; 87 OwnershipService* service_;
107 88
108 private: 89 private:
109 friend class SignedSettingsTest; 90 friend class SignedSettingsTest;
110 friend class SignedSettingsHelperTest; 91 friend class SignedSettingsHelperTest;
111 92
112 class Relay
113 : public SignedSettings::Delegate<const em::PolicyFetchResponse&> {
114 public:
115 // |s| must outlive your Relay instance.
116 explicit Relay(SignedSettings* s);
117 virtual ~Relay();
118 // Implementation of SignedSettings::Delegate
119 virtual void OnSettingsOpCompleted(
120 SignedSettings::ReturnCode code,
121 const em::PolicyFetchResponse& value) OVERRIDE;
122 private:
123 SignedSettings* settings_;
124 DISALLOW_COPY_AND_ASSIGN(Relay);
125 };
126
127 // Format of this string is documented in device_management_backend.proto.
128 static const char kDevicePolicyType[];
129
130 scoped_ptr<Relay> relay_;
131 scoped_refptr<SignedSettings> polfetcher_;
132 DISALLOW_COPY_AND_ASSIGN(SignedSettings); 93 DISALLOW_COPY_AND_ASSIGN(SignedSettings);
133 }; 94 };
134 95
135 } // namespace chromeos 96 } // namespace chromeos
136 97
137 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ 98 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698