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

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

Issue 3141031: [Chrome OS] Wire up ownership API from libcros (Closed)
Patch Set: address davemoore comments Created 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/cros/login_library.h" 5 #include "chrome/browser/chromeos/cros/login_library.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "chrome/browser/chrome_thread.h" 8 #include "chrome/browser/chrome_thread.h"
9 #include "chrome/browser/chromeos/cros/cros_library.h" 9 #include "chrome/browser/chromeos/cros/cros_library.h"
10 10
11 namespace chromeos { 11 namespace chromeos {
12 12
13 class LoginLibraryImpl : public LoginLibrary { 13 class LoginLibraryImpl : public LoginLibrary {
14 public: 14 public:
15 LoginLibraryImpl() {} 15 LoginLibraryImpl()
16 virtual ~LoginLibraryImpl() {} 16 : set_owner_key_callback_(NULL) {
17 }
18 virtual ~LoginLibraryImpl() {
19 if (session_connection_) {
20 chromeos::DisconnectSession(session_connection_);
21 }
22 }
17 23
18 bool EmitLoginPromptReady() { 24 bool EmitLoginPromptReady() {
19 return chromeos::EmitLoginPromptReady(); 25 return chromeos::EmitLoginPromptReady();
20 } 26 }
21 27
28 bool SetOwnerKey(const std::vector<uint8>& public_key_der,
29 Delegate<bool>* callback) {
30 DCHECK(callback) << "must provide a callback to SetOwnerKey()";
31 set_owner_key_callback_ = callback;
32 return chromeos::SetOwnerKey(public_key_der);
33 }
34
22 bool StartSession(const std::string& user_email, 35 bool StartSession(const std::string& user_email,
23 const std::string& unique_id /* unused */) { 36 const std::string& unique_id /* unused */) {
24 // only pass unique_id through once we use it for something. 37 // only pass unique_id through once we use it for something.
25 return chromeos::StartSession(user_email.c_str(), ""); 38 return chromeos::StartSession(user_email.c_str(), "");
26 } 39 }
27 40
28 bool StopSession(const std::string& unique_id /* unused */) { 41 bool StopSession(const std::string& unique_id /* unused */) {
29 // only pass unique_id through once we use it for something. 42 // only pass unique_id through once we use it for something.
30 return chromeos::StopSession(""); 43 return chromeos::StopSession("");
31 } 44 }
32 45
33 bool RestartJob(int pid, const std::string& command_line) { 46 bool RestartJob(int pid, const std::string& command_line) {
34 return chromeos::RestartJob(pid, command_line.c_str()); 47 return chromeos::RestartJob(pid, command_line.c_str());
35 } 48 }
36 49
37 private: 50 private:
51 static void Handler(void* object, const OwnershipEvent& event) {
52 LoginLibraryImpl* self = static_cast<LoginLibraryImpl*>(object);
53 switch (event) {
54 case SetKeySuccess:
55 self->CompleteSetOwnerKey(true);
56 break;
57 case SetKeyFailure:
58 self->CompleteSetOwnerKey(false);
59 break;
60 case WhitelistOpSuccess:
61 case WhitelistOpFailure:
62 case SettingsOpSuccess:
63 case SettingsOpFailure:
64 NOTIMPLEMENTED();
65 break;
66 default:
67 NOTREACHED();
68 }
69 }
70
71 void Init() {
72 session_connection_ = chromeos::MonitorSession(&Handler, this);
73 }
74
75 void CompleteSetOwnerKey(bool result) {
76 CHECK(set_owner_key_callback_) << "CompleteSetOwnerKey() called without "
77 "a registered callback!";
78 set_owner_key_callback_->Run(result);
79 set_owner_key_callback_ = NULL;
80 }
81
82 chromeos::SessionConnection session_connection_;
83
84 Delegate<bool>* set_owner_key_callback_;
85
38 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl); 86 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl);
39 }; 87 };
40 88
41 class LoginLibraryStubImpl : public LoginLibrary { 89 class LoginLibraryStubImpl : public LoginLibrary {
42 public: 90 public:
43 LoginLibraryStubImpl() {} 91 LoginLibraryStubImpl() {}
44 virtual ~LoginLibraryStubImpl() {} 92 virtual ~LoginLibraryStubImpl() {}
45 93
46 bool EmitLoginPromptReady() { return true; } 94 bool EmitLoginPromptReady() { return true; }
95 bool SetOwnerKey(const std::vector<uint8>& public_key_der,
96 Delegate<bool>* callback) {
97 ChromeThread::PostTask(
98 ChromeThread::UI, FROM_HERE,
99 NewRunnableFunction(&SetOwnerKeyStubCallback, callback));
100 return true;
101 }
47 bool StartSession(const std::string& user_email, 102 bool StartSession(const std::string& user_email,
48 const std::string& unique_id /* unused */) { return true; } 103 const std::string& unique_id /* unused */) { return true; }
49 bool StopSession(const std::string& unique_id /* unused */) { return true; } 104 bool StopSession(const std::string& unique_id /* unused */) { return true; }
50 bool RestartJob(int pid, const std::string& command_line) { return true; } 105 bool RestartJob(int pid, const std::string& command_line) { return true; }
51 106
52 private: 107 private:
108 static void SetOwnerKeyStubCallback(Delegate<bool>* callback) {
109 callback->Run(true);
110 }
111
53 DISALLOW_COPY_AND_ASSIGN(LoginLibraryStubImpl); 112 DISALLOW_COPY_AND_ASSIGN(LoginLibraryStubImpl);
54 }; 113 };
55 114
56 // static 115 // static
57 LoginLibrary* LoginLibrary::GetImpl(bool stub) { 116 LoginLibrary* LoginLibrary::GetImpl(bool stub) {
58 if (stub) 117 if (stub)
59 return new LoginLibraryStubImpl(); 118 return new LoginLibraryStubImpl();
60 else 119 else
61 return new LoginLibraryImpl(); 120 return new LoginLibraryImpl();
62 } 121 }
63 122
64 } // namespace chromeos 123 } // 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