OLD | NEW |
| (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/session_manager_observer.h" | |
6 | |
7 #include "chrome/browser/browser_process.h" | |
8 #include "chrome/browser/chromeos/login/signed_settings.h" | |
9 #include "chrome/browser/chromeos/login/signed_settings_cache.h" | |
10 #include "chrome/common/chrome_notification_types.h" | |
11 #include "chromeos/dbus/dbus_thread_manager.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "content/public/browser/notification_service.h" | |
14 | |
15 namespace chromeos { | |
16 | |
17 namespace { | |
18 | |
19 class StubDelegate | |
20 : public SignedSettings::Delegate< | |
21 const enterprise_management::PolicyFetchResponse&> { | |
22 public: | |
23 StubDelegate() : policy_fetcher_(NULL) {} | |
24 virtual ~StubDelegate() {} | |
25 | |
26 void set_fetcher(SignedSettings* fetcher) { policy_fetcher_ = fetcher; } | |
27 SignedSettings* fetcher() { return policy_fetcher_.get(); } | |
28 | |
29 // Implementation of SignedSettings::Delegate | |
30 virtual void OnSettingsOpCompleted( | |
31 SignedSettings::ReturnCode code, | |
32 const enterprise_management::PolicyFetchResponse& value) { | |
33 VLOG(1) << "Done Fetching Policy"; | |
34 delete this; | |
35 } | |
36 | |
37 private: | |
38 scoped_refptr<SignedSettings> policy_fetcher_; | |
39 DISALLOW_COPY_AND_ASSIGN(StubDelegate); | |
40 }; | |
41 | |
42 } // namespace | |
43 | |
44 SessionManagerObserver::SessionManagerObserver() { | |
45 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); | |
46 } | |
47 | |
48 SessionManagerObserver::~SessionManagerObserver() { | |
49 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); | |
50 } | |
51 | |
52 void SessionManagerObserver::OwnerKeySet(bool success) { | |
53 VLOG(1) << "Owner key generation: " << (success ? "success" : "fail"); | |
54 int result = | |
55 chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; | |
56 if (!success) | |
57 result = chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_FAILED; | |
58 | |
59 // We stored some settings in transient storage before owner was assigned. | |
60 // Now owner is assigned and key is generated and we should persist | |
61 // those settings into signed storage. | |
62 if (success && g_browser_process && g_browser_process->local_state()) | |
63 signed_settings_cache::Finalize(g_browser_process->local_state()); | |
64 | |
65 // Whether we exported the public key or not, send a notification | |
66 // indicating that we're done with this attempt. | |
67 content::NotificationService::current()->Notify( | |
68 result, | |
69 content::NotificationService::AllSources(), | |
70 content::NotificationService::NoDetails()); | |
71 } | |
72 | |
73 void SessionManagerObserver::PropertyChangeComplete(bool success) { | |
74 if (success) { | |
75 StubDelegate* stub = new StubDelegate(); // Manages its own lifetime. | |
76 stub->set_fetcher(SignedSettings::CreateRetrievePolicyOp(stub)); | |
77 stub->fetcher()->Execute(); | |
78 } | |
79 } | |
80 | |
81 } // namespace chromeos | |
OLD | NEW |