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

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

Issue 2801993002: Abandon user sign in when policy is retrieved before session started (Closed)
Patch Set: Fixed review comments Created 3 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 5 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/threading/sequenced_worker_pool.h" 9 #include "base/threading/sequenced_worker_pool.h"
10 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 10 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
11 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 11 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
12 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 12 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
13 #include "chrome/browser/chromeos/profiles/profile_helper.h" 13 #include "chrome/browser/chromeos/profiles/profile_helper.h"
14 #include "chrome/browser/chromeos/settings/device_settings_service.h" 14 #include "chrome/browser/chromeos/settings/device_settings_service.h"
15 #include "chrome/test/base/testing_browser_process.h" 15 #include "chrome/test/base/testing_browser_process.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "chromeos/cryptohome/cryptohome_parameters.h" 17 #include "chromeos/cryptohome/cryptohome_parameters.h"
18 #include "chromeos/dbus/dbus_thread_manager.h" 18 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "components/ownership/mock_owner_key_util.h" 19 #include "components/ownership/mock_owner_key_util.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/test/test_utils.h" 21 #include "content/public/test/test_utils.h"
22 22
23 using RetrievePolicyResponseType =
24 chromeos::DeviceSettingsTestHelper::RetrievePolicyResponseType;
25
23 namespace chromeos { 26 namespace chromeos {
24 27
25 DeviceSettingsTestHelper::DeviceSettingsTestHelper() {} 28 DeviceSettingsTestHelper::DeviceSettingsTestHelper() {}
26 29
27 DeviceSettingsTestHelper::~DeviceSettingsTestHelper() {} 30 DeviceSettingsTestHelper::~DeviceSettingsTestHelper() {}
28 31
29 void DeviceSettingsTestHelper::FlushStore() { 32 void DeviceSettingsTestHelper::FlushStore() {
30 std::vector<StorePolicyCallback> callbacks; 33 std::vector<StorePolicyCallback> callbacks;
31 callbacks.swap(device_policy_.store_callbacks_); 34 callbacks.swap(device_policy_.store_callbacks_);
32 for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin()); 35 for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin());
(...skipping 11 matching lines...) Expand all
44 cb->Run(device_local_account_state->second.store_result_); 47 cb->Run(device_local_account_state->second.store_result_);
45 } 48 }
46 } 49 }
47 } 50 }
48 51
49 void DeviceSettingsTestHelper::FlushRetrieve() { 52 void DeviceSettingsTestHelper::FlushRetrieve() {
50 std::vector<RetrievePolicyCallback> callbacks; 53 std::vector<RetrievePolicyCallback> callbacks;
51 callbacks.swap(device_policy_.retrieve_callbacks_); 54 callbacks.swap(device_policy_.retrieve_callbacks_);
52 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin()); 55 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin());
53 cb != callbacks.end(); ++cb) { 56 cb != callbacks.end(); ++cb) {
54 cb->Run(device_policy_.policy_blob_); 57 cb->Run(device_policy_.policy_blob_, RetrievePolicyResponseType::SUCCESS);
55 } 58 }
56 59
57 std::map<std::string, PolicyState>::iterator device_local_account_state; 60 std::map<std::string, PolicyState>::iterator device_local_account_state;
58 for (device_local_account_state = device_local_account_policy_.begin(); 61 for (device_local_account_state = device_local_account_policy_.begin();
59 device_local_account_state != device_local_account_policy_.end(); 62 device_local_account_state != device_local_account_policy_.end();
60 ++device_local_account_state) { 63 ++device_local_account_state) {
61 std::vector<RetrievePolicyCallback> callbacks; 64 std::vector<RetrievePolicyCallback> callbacks;
62 callbacks.swap(device_local_account_state->second.retrieve_callbacks_); 65 callbacks.swap(device_local_account_state->second.retrieve_callbacks_);
63 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin()); 66 for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin());
64 cb != callbacks.end(); ++cb) { 67 cb != callbacks.end(); ++cb) {
65 cb->Run(device_local_account_state->second.policy_blob_); 68 cb->Run(device_local_account_state->second.policy_blob_,
69 RetrievePolicyResponseType::SUCCESS);
66 } 70 }
67 } 71 }
68 } 72 }
69 73
70 void DeviceSettingsTestHelper::Flush() { 74 void DeviceSettingsTestHelper::Flush() {
71 do { 75 do {
72 content::RunAllBlockingPoolTasksUntilIdle(); 76 content::RunAllBlockingPoolTasksUntilIdle();
73 FlushStore(); 77 FlushStore();
74 content::RunAllBlockingPoolTasksUntilIdle(); 78 content::RunAllBlockingPoolTasksUntilIdle();
75 FlushRetrieve(); 79 FlushRetrieve();
(...skipping 14 matching lines...) Expand all
90 } 94 }
91 95
92 return false; 96 return false;
93 } 97 }
94 98
95 void DeviceSettingsTestHelper::RetrieveDevicePolicy( 99 void DeviceSettingsTestHelper::RetrieveDevicePolicy(
96 const RetrievePolicyCallback& callback) { 100 const RetrievePolicyCallback& callback) {
97 device_policy_.retrieve_callbacks_.push_back(callback); 101 device_policy_.retrieve_callbacks_.push_back(callback);
98 } 102 }
99 103
100 std::string DeviceSettingsTestHelper::BlockingRetrieveDevicePolicy() { 104 RetrievePolicyResponseType
101 return device_policy_.policy_blob_; 105 DeviceSettingsTestHelper::BlockingRetrieveDevicePolicy(
106 std::string* policy_out) {
107 *policy_out = device_policy_.policy_blob_;
108 return RetrievePolicyResponseType::SUCCESS;
102 } 109 }
103 110
104 void DeviceSettingsTestHelper::RetrieveDeviceLocalAccountPolicy( 111 void DeviceSettingsTestHelper::RetrieveDeviceLocalAccountPolicy(
105 const std::string& account_id, 112 const std::string& account_id,
106 const RetrievePolicyCallback& callback) { 113 const RetrievePolicyCallback& callback) {
107 device_local_account_policy_[account_id].retrieve_callbacks_.push_back( 114 device_local_account_policy_[account_id].retrieve_callbacks_.push_back(
108 callback); 115 callback);
109 } 116 }
110 117
111 std::string DeviceSettingsTestHelper::BlockingRetrieveDeviceLocalAccountPolicy( 118 RetrievePolicyResponseType
112 const std::string& account_id) { 119 DeviceSettingsTestHelper::BlockingRetrieveDeviceLocalAccountPolicy(
113 return ""; 120 const std::string& account_id,
121 std::string* policy_out) {
122 *policy_out = "";
123 return RetrievePolicyResponseType::SUCCESS;
114 } 124 }
115 125
116 void DeviceSettingsTestHelper::StoreDevicePolicy( 126 void DeviceSettingsTestHelper::StoreDevicePolicy(
117 const std::string& policy_blob, 127 const std::string& policy_blob,
118 const StorePolicyCallback& callback) { 128 const StorePolicyCallback& callback) {
119 device_policy_.policy_blob_ = policy_blob; 129 device_policy_.policy_blob_ = policy_blob;
120 device_policy_.store_callbacks_.push_back(callback); 130 device_policy_.store_callbacks_.push_back(callback);
121 } 131 }
122 132
123 void DeviceSettingsTestHelper::StoreDeviceLocalAccountPolicy( 133 void DeviceSettingsTestHelper::StoreDeviceLocalAccountPolicy(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 const_cast<user_manager::User*>(user)); 220 const_cast<user_manager::User*>(user));
211 } 221 }
212 OwnerSettingsServiceChromeOS* service = 222 OwnerSettingsServiceChromeOS* service =
213 OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(profile_.get()); 223 OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(profile_.get());
214 CHECK(service); 224 CHECK(service);
215 if (tpm_is_ready) 225 if (tpm_is_ready)
216 service->OnTPMTokenReady(true /* token is enabled */); 226 service->OnTPMTokenReady(true /* token is enabled */);
217 } 227 }
218 228
219 } // namespace chromeos 229 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698