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

Side by Side Diff: chrome/browser/chromeos/login/device_settings_test_helper.cc

Issue 10828032: Add DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Oops. Created 8 years, 4 months 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
(Empty)
1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/login/device_settings_test_helper.h"
6
7 #include "base/message_loop.h"
8 #include "base/threading/sequenced_worker_pool.h"
9 #include "chrome/browser/chromeos/login/device_settings_service.h"
10 #include "chrome/browser/chromeos/login/mock_owner_key_util.h"
11 #include "content/public/browser/browser_thread.h"
12
13 namespace chromeos {
14
15 DeviceSettingsTestHelper::DeviceSettingsTestHelper()
16 : store_result_(true) {}
17
18 DeviceSettingsTestHelper::~DeviceSettingsTestHelper() {}
19
20 void DeviceSettingsTestHelper::FlushStore() {
21 do {
22 FlushLoops();
23 std::vector<StorePolicyCallback> callbacks;
24 callbacks.swap(store_callbacks_);
25 for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin());
26 cb != callbacks.end(); ++cb) {
27 cb->Run(store_result_);
28 FlushLoops();
29 }
30 } while (!store_callbacks_.empty());
31 }
32
33 void DeviceSettingsTestHelper::FlushRetrieve() {
34 do {
35 FlushLoops();
36 std::vector<RetrievePolicyCallback> callbacks;
37 callbacks.swap(retrieve_callbacks_);
38 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin());
39 cb != callbacks.end(); ++cb) {
40 cb->Run(policy_blob_);
41 FlushLoops();
42 }
43 } while (!retrieve_callbacks_.empty());
44 }
45
46 void DeviceSettingsTestHelper::Flush() {
47 do {
48 FlushStore();
49 FlushRetrieve();
50 } while (!store_callbacks_.empty());
51 }
52
53 void DeviceSettingsTestHelper::FlushLoops() {
54 // DeviceSettingsService may trigger operations that hop back and forth
55 // between the message loop and the blocking pool. 2 iterations are currently
56 // sufficient (key loading, signing).
57 for (int i = 0; i < 2; ++i) {
pastarmovj 2012/07/30 12:19:19 Any chance this can be replaced with a while(has_p
Mattias Nissler (ping if slow) 2012/07/31 13:02:15 No, there's no good way to find out for the blocki
58 MessageLoop::current()->RunAllPending();
59 content::BrowserThread::GetBlockingPool()->FlushForTesting();
60 }
61 MessageLoop::current()->RunAllPending();
62 }
63
64 void DeviceSettingsTestHelper::AddObserver(Observer* observer) {}
65
66 void DeviceSettingsTestHelper::RemoveObserver(Observer* observer) {}
67
68 bool DeviceSettingsTestHelper::HasObserver(Observer* observer) {
69 return false;
70 }
71
72 void DeviceSettingsTestHelper::EmitLoginPromptReady() {}
73
74 void DeviceSettingsTestHelper::EmitLoginPromptVisible() {}
75
76 void DeviceSettingsTestHelper::RestartJob(int pid,
77 const std::string& command_line) {}
78
79 void DeviceSettingsTestHelper::RestartEntd() {}
80
81 void DeviceSettingsTestHelper::StartSession(const std::string& user_email) {}
82
83 void DeviceSettingsTestHelper::StopSession() {}
84
85 void DeviceSettingsTestHelper::RequestLockScreen() {}
86
87 void DeviceSettingsTestHelper::RequestUnlockScreen() {}
88
89 bool DeviceSettingsTestHelper::GetIsScreenLocked() {
90 return false;
91 }
92
93 void DeviceSettingsTestHelper::RetrieveDevicePolicy(
94 const RetrievePolicyCallback& callback) {
95 retrieve_callbacks_.push_back(callback);
96 }
97
98 void DeviceSettingsTestHelper::RetrieveUserPolicy(
99 const RetrievePolicyCallback& callback) {
100 }
101
102 void DeviceSettingsTestHelper::StoreDevicePolicy(
103 const std::string& policy_blob,
104 const StorePolicyCallback& callback) {
105 policy_blob_ = policy_blob;
106 store_callbacks_.push_back(callback);
107 }
108
109 void DeviceSettingsTestHelper::StoreUserPolicy(
110 const std::string& policy_blob,
111 const StorePolicyCallback& callback) {}
112
113 ScopedDeviceSettingsTestHelper::ScopedDeviceSettingsTestHelper() {
114 DeviceSettingsService::Get()->Initialize(this, new MockOwnerKeyUtil());
115 DeviceSettingsService::Get()->Load();
116 Flush();
117 }
118
119 ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() {
120 Flush();
121 DeviceSettingsService::Get()->Shutdown();
122 }
123
124 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698