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

Side by Side Diff: chrome/browser/automation/automation_provider_observers_chromeos.cc

Issue 6732040: PyAuto automation hooks: blocking wifi connect, disconnect, and network scan. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial commit. Created 9 years, 9 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/automation/automation_provider_observers.h"
dennis_jeffrey 2011/03/24 23:48:54 Is there a reason why this include is separated fr
dtu 2011/03/25 22:22:11 The main purpose of this file is to implement meth
dennis_jeffrey 2011/03/25 22:44:36 Cool, thanks for the link.
6
7 #include "base/values.h"
8 #include "chrome/browser/automation/automation_provider.h"
9 #include "chrome/browser/chromeos/cros/cros_library.h"
10 #include "chrome/browser/chromeos/login/authentication_notification_details.h"
11 #include "content/common/notification_service.h"
12
13 using chromeos::CrosLibrary;
14 using chromeos::NetworkLibrary;
15
16 NetworkManagerInitObserver::NetworkManagerInitObserver(
17 AutomationProvider* automation)
18 : automation_(automation->AsWeakPtr()) {
19 if (CrosLibrary::Get()->EnsureLoaded()) {
20 CrosLibrary::Get()->GetNetworkLibrary()->
21 AddNetworkManagerObserver(this);
22 } else {
23 automation_->OnNetworkLibraryInit();
24 delete this;
stevenjb 2011/03/25 01:12:22 Is deletion in the constructor a pattern we use el
dtu 2011/03/25 22:22:11 Done.
25 }
26 }
27
28 NetworkManagerInitObserver::~NetworkManagerInitObserver() {}
stevenjb 2011/03/25 01:12:22 Should call RemoveNetworkManagerObserver() here in
dtu 2011/03/25 22:22:11 Done.
29
30 void NetworkManagerInitObserver::OnNetworkManagerChanged(NetworkLibrary* obj) {
31 if (!obj->wifi_scanning()) {
32 obj->RemoveNetworkManagerObserver(this);
stevenjb 2011/03/25 01:12:22 Do this in the destructor.
dtu 2011/03/25 22:22:11 Done.
33 automation_->OnNetworkLibraryInit();
34 delete this;
35 }
36 }
37
38 LoginManagerObserver::LoginManagerObserver(
39 AutomationProvider* automation,
40 IPC::Message* reply_message)
41 : automation_(automation->AsWeakPtr()),
42 reply_message_(reply_message) {
43
dennis_jeffrey 2011/03/24 23:48:54 Delete this blank line.
dtu 2011/03/25 22:22:11 Done.
44 registrar_.Add(this, NotificationType::LOGIN_USER_CHANGED,
45 NotificationService::AllSources());
46 }
47
48 LoginManagerObserver::~LoginManagerObserver() {}
49
50 void LoginManagerObserver::Observe(NotificationType type,
51 const NotificationSource& source,
52 const NotificationDetails& details) {
53 DCHECK(type == NotificationType::LOGIN_USER_CHANGED);
54
55 if (!automation_) {
56 delete this;
57 return;
58 }
59
60 AutomationJSONReply reply(automation_, reply_message_.release());
61 Details<AuthenticationNotificationDetails> auth_details(details);
62 if (auth_details->success())
63 reply.SendSuccess(NULL);
64 else
65 reply.SendError("Login failure.");
66 delete this;
67 }
68
69 ScreenLockUnlockObserver::ScreenLockUnlockObserver(
70 AutomationProvider* automation,
71 IPC::Message* reply_message,
72 bool lock_screen)
73 : automation_(automation),
74 reply_message_(reply_message),
75 lock_screen_(lock_screen) {
76
dennis_jeffrey 2011/03/24 23:48:54 Delete this blank line.
dtu 2011/03/25 22:22:11 Done.
77 registrar_.Add(this, NotificationType::SCREEN_LOCK_STATE_CHANGED,
78 NotificationService::AllSources());
79 }
80
81 ScreenLockUnlockObserver::~ScreenLockUnlockObserver() {}
82
83 void ScreenLockUnlockObserver::Observe(NotificationType type,
84 const NotificationSource& source,
85 const NotificationDetails& details) {
86 DCHECK(type == NotificationType::SCREEN_LOCK_STATE_CHANGED);
87 AutomationJSONReply reply(automation_, reply_message_);
88 bool is_screen_locked = *Details<bool>(details).ptr();
89 if (lock_screen_ == is_screen_locked)
90 reply.SendSuccess(NULL);
91 else
92 reply.SendError("Screen lock failure.");
93 delete this;
94 }
95
96 NetworkScanObserver::NetworkScanObserver(AutomationProvider* automation,
97 IPC::Message* reply_message)
dennis_jeffrey 2011/03/24 23:48:54 Indent underneath the first parameter in the previ
dtu 2011/03/25 22:22:11 Done.
98 : automation_(automation), reply_message_(reply_message) {
dennis_jeffrey 2011/03/24 23:48:54 I think in other parts of the code, this line is g
dtu 2011/03/25 22:22:11 Done.
99 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
dennis_jeffrey 2011/03/24 23:48:54 Are we guaranteed that "network_library" will refe
stevenjb 2011/03/25 01:12:22 GetNetworkLibrary() will always return a valid ins
100 network_library->AddNetworkManagerObserver(this);
101 }
102
103 NetworkScanObserver::~NetworkScanObserver() {
104 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
dennis_jeffrey 2011/03/24 23:48:54 Same comment as line 99 above.
dtu 2011/03/25 22:22:11 Yes, see stevenjb's comment on line 99 above.
105 network_library->RemoveNetworkManagerObserver(this);
106 }
107
108 void NetworkScanObserver::OnNetworkManagerChanged(NetworkLibrary* obj) {
109 if (obj->wifi_scanning())
110 return;
111
112 AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL);
113 delete this;
114 }
115
116 NetworkConnectObserver::NetworkConnectObserver(AutomationProvider* automation,
117 IPC::Message* reply_message,
118 chromeos::Network* network)
119 : automation_(automation), reply_message_(reply_message), network_(network) {
dennis_jeffrey 2011/03/24 23:48:54 Same comment as line 98 above.
stevenjb 2011/03/25 01:12:22 I am not sure where this is called from, but we sh
dtu 2011/03/25 22:22:11 Done.
dtu 2011/03/25 22:22:11 Done.
120 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
dennis_jeffrey 2011/03/24 23:48:54 Same comment as line 99 above.
dtu 2011/03/25 22:22:11 Same reply as line 99 above.
121 network_library->AddNetworkManagerObserver(this);
122 }
123
124 NetworkConnectObserver::~NetworkConnectObserver() {
125 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
dennis_jeffrey 2011/03/24 23:48:54 Same comment as line 99 above.
dtu 2011/03/25 22:22:11 Same reply as line 99 above.
126 network_library->RemoveNetworkManagerObserver(this);
127 }
128
129 void NetworkConnectObserver::OnNetworkManagerChanged(NetworkLibrary* obj) {
130 if (network_->failed()) {
stevenjb 2011/03/25 01:12:22 See note above about saving Network *'s. Use: Netw
dtu 2011/03/25 22:22:11 Done.
131 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
132 return_value->SetInteger("error_code", network_->error());
133 AutomationJSONReply reply(automation_, reply_message_);
134 reply.SendSuccess(return_value.get());
135 delete this;
136 }
137 if (network_->connected()) {
138 AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL);
139 delete this;
140 }
dennis_jeffrey 2011/03/24 23:48:54 Is it possible for the conditions at lines 130 and
stevenjb 2011/03/25 01:12:22 This gets called any time anything in the network
141 }
142
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698