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

Side by Side Diff: chrome/browser/chromeos/cros/login_library.cc

Issue 8305015: chromeos: Remove LoginLibrary code, which is no longer used. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 2 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) 2011 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/cros/login_library.h"
6
7 #include "base/message_loop.h"
8 #include "base/timer.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chromeos/cros/cros_library.h"
11 #include "chrome/browser/chromeos/login/signed_settings.h"
12 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h"
13 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/common/chrome_notification_types.h"
16 #include "content/browser/browser_thread.h"
17 #include "content/common/notification_service.h"
18
19 namespace em = enterprise_management;
20 namespace chromeos {
21
22 LoginLibrary::~LoginLibrary() {}
23
24 class LoginLibraryImpl : public LoginLibrary {
25 public:
26 LoginLibraryImpl() {
27 }
28
29 virtual ~LoginLibraryImpl() {
30 if (session_connection_) {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
32 chromeos::DisconnectSession(session_connection_);
33 }
34 }
35
36 virtual void Init() OVERRIDE {
37 DCHECK(CrosLibrary::Get()->libcros_loaded());
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
39 session_connection_ = chromeos::MonitorSession(&Handler, this);
40 }
41
42 virtual void EmitLoginPromptReady() OVERRIDE {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
44 chromeos::EmitLoginPromptReady();
45 }
46
47 virtual void EmitLoginPromptVisible() OVERRIDE {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49 chromeos::EmitLoginPromptVisible();
50 }
51
52 virtual void RequestRetrievePolicy(
53 RetrievePolicyCallback callback, void* delegate) OVERRIDE {
54 DCHECK(callback) << "must provide a callback to RequestRetrievePolicy()";
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56 chromeos::RetrievePolicy(callback, delegate);
57 }
58
59 virtual void RequestStorePolicy(const std::string& policy,
60 StorePolicyCallback callback,
61 void* delegate) OVERRIDE {
62 DCHECK(callback) << "must provide a callback to StorePolicy()";
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
64 chromeos::StorePolicy(policy.c_str(), policy.length(), callback, delegate);
65 }
66
67 virtual void StartSession(
68 const std::string& user_email,
69 const std::string& unique_id /* unused */) OVERRIDE {
70 // only pass unique_id through once we use it for something.
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
72 chromeos::StartSession(user_email.c_str(), "");
73 }
74
75 virtual void StopSession(const std::string& unique_id /* unused */) OVERRIDE {
76 // only pass unique_id through once we use it for something.
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
78 chromeos::StopSession("");
79 }
80
81 virtual void RestartEntd() OVERRIDE {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
83 chromeos::RestartEntd();
84 }
85
86 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
88 chromeos::RestartJob(pid, command_line.c_str());
89 }
90
91 class StubDelegate
92 : public SignedSettings::Delegate<const em::PolicyFetchResponse&> {
93 public:
94 StubDelegate() : polfetcher_(NULL) {}
95 virtual ~StubDelegate() {}
96 void set_fetcher(SignedSettings* s) { polfetcher_ = s; }
97 SignedSettings* fetcher() { return polfetcher_.get(); }
98 // Implementation of SignedSettings::Delegate
99 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code,
100 const em::PolicyFetchResponse& value) {
101 VLOG(2) << "Done Fetching Policy";
102 delete this;
103 }
104 private:
105 scoped_refptr<SignedSettings> polfetcher_;
106 DISALLOW_COPY_AND_ASSIGN(StubDelegate);
107 };
108
109 static void Handler(void* object, const OwnershipEvent& event) {
110 LoginLibraryImpl* self = static_cast<LoginLibraryImpl*>(object);
111 switch (event) {
112 case SetKeySuccess:
113 self->CompleteSetOwnerKey(true);
114 break;
115 case SetKeyFailure:
116 self->CompleteSetOwnerKey(false);
117 break;
118 case WhitelistOpSuccess:
119 self->CompleteWhitelistOp(true);
120 break;
121 case WhitelistOpFailure:
122 self->CompleteWhitelistOp(false);
123 break;
124 case PropertyOpSuccess:
125 self->CompletePropertyOp(true);
126 break;
127 case PropertyOpFailure:
128 self->CompletePropertyOp(false);
129 break;
130 default:
131 NOTREACHED();
132 break;
133 }
134 }
135
136 void CompleteSetOwnerKey(bool value) {
137 VLOG(1) << "Owner key generation: " << (value ? "success" : "fail");
138 int result =
139 chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED;
140 if (!value)
141 result = chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_FAILED;
142
143 // Whether we exported the public key or not, send a notification indicating
144 // that we're done with this attempt.
145 NotificationService::current()->Notify(result,
146 NotificationService::AllSources(),
147 NotificationService::NoDetails());
148
149 // We stored some settings in transient storage before owner was assigned.
150 // Now owner is assigned and key is generated and we should persist
151 // those settings into signed storage.
152 if (g_browser_process && g_browser_process->local_state()) {
153 SignedSettingsTempStorage::Finalize(g_browser_process->local_state());
154 }
155 }
156
157 void CompleteWhitelistOp(bool result) {
158 // DEPRECATED.
159 }
160
161 void CompletePropertyOp(bool result) {
162 if (result) {
163 StubDelegate* stub = new StubDelegate(); // Manages its own lifetime.
164 stub->set_fetcher(SignedSettings::CreateRetrievePolicyOp(stub));
165 stub->fetcher()->Execute();
166 }
167 }
168
169 chromeos::SessionConnection session_connection_;
170
171 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl);
172 };
173
174 class LoginLibraryStubImpl : public LoginLibrary {
175 public:
176 LoginLibraryStubImpl() {}
177 virtual ~LoginLibraryStubImpl() {}
178
179 virtual void Init() OVERRIDE {}
180
181 virtual void EmitLoginPromptReady() OVERRIDE {}
182 virtual void EmitLoginPromptVisible() OVERRIDE {}
183 virtual void RequestRetrievePolicy(
184 RetrievePolicyCallback callback, void* delegate) OVERRIDE {
185 callback(delegate, "", 0);
186 }
187 virtual void RequestStorePolicy(const std::string& policy,
188 StorePolicyCallback callback,
189 void* delegate) OVERRIDE {
190 callback(delegate, true);
191 }
192 virtual void StartSession(
193 const std::string& user_email,
194 const std::string& unique_id /* unused */) OVERRIDE {
195 }
196 virtual void StopSession(const std::string& unique_id /* unused */) OVERRIDE {
197 }
198 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {
199 }
200 virtual void RestartEntd() OVERRIDE {}
201
202 private:
203 DISALLOW_COPY_AND_ASSIGN(LoginLibraryStubImpl);
204 };
205
206 // static
207 LoginLibrary* LoginLibrary::GetImpl(bool stub) {
208 LoginLibrary* impl;
209 if (stub)
210 impl = new LoginLibraryStubImpl();
211 else
212 impl = new LoginLibraryImpl();
213 impl->Init();
214 return impl;
215 }
216
217 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/login_library.h ('k') | chrome/browser/chromeos/cros/mock_login_library.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698