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

Side by Side Diff: chrome/browser/extensions/api/gcd_private/gcd_private_api.cc

Issue 608473004: Support minimal use case for gcdPrivate.sendMessage('/privet/v3/setup/start') on linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/extensions/api/gcd_private/gcd_private_api.h" 5 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/linked_ptr.h" 8 #include "base/memory/linked_ptr.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 24 matching lines...) Expand all
35 namespace gcd_private = api::gcd_private; 35 namespace gcd_private = api::gcd_private;
36 36
37 namespace { 37 namespace {
38 38
39 const int kNumRequestsNeeded = 2; 39 const int kNumRequestsNeeded = 2;
40 40
41 const char kIDPrefixCloudPrinter[] = "cloudprint:"; 41 const char kIDPrefixCloudPrinter[] = "cloudprint:";
42 const char kIDPrefixGcd[] = "gcd:"; 42 const char kIDPrefixGcd[] = "gcd:";
43 const char kIDPrefixMdns[] = "mdns:"; 43 const char kIDPrefixMdns[] = "mdns:";
44 44
45 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
46 const char kPrivatAPISetup[] = "/privet/v3/setup/start"; 45 const char kPrivatAPISetup[] = "/privet/v3/setup/start";
47 const char kPrivetKeyWifi[] = "wifi"; 46 const char kPrivetKeyWifi[] = "wifi";
48 const char kPrivetKeyPassphrase[] = "passphrase"; 47 const char kPrivetKeyPassphrase[] = "passphrase";
49 const char kPrivetKeySSID[] = "ssid"; 48 const char kPrivetKeySSID[] = "ssid";
50 const char kPrivetKeyPassphraseDotted[] = "wifi.passphrase"; 49 const char kPrivetKeyPassphraseDotted[] = "wifi.passphrase";
51 #endif // ENABLE_WIFI_BOOTSTRAPPING
52 50
53 scoped_ptr<Event> MakeDeviceStateChangedEvent( 51 scoped_ptr<Event> MakeDeviceStateChangedEvent(
54 const gcd_private::GCDDevice& device) { 52 const gcd_private::GCDDevice& device) {
55 scoped_ptr<base::ListValue> params = 53 scoped_ptr<base::ListValue> params =
56 gcd_private::OnDeviceStateChanged::Create(device); 54 gcd_private::OnDeviceStateChanged::Create(device);
57 scoped_ptr<Event> event( 55 scoped_ptr<Event> event(
58 new Event(gcd_private::OnDeviceStateChanged::kEventName, params.Pass())); 56 new Event(gcd_private::OnDeviceStateChanged::kEventName, params.Pass()));
59 return event.Pass(); 57 return event.Pass();
60 } 58 }
61 59
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 scoped_ptr<local_discovery::PrivetDeviceLister> privet_device_lister_; 179 scoped_ptr<local_discovery::PrivetDeviceLister> privet_device_lister_;
182 GCDDeviceMap known_devices_; 180 GCDDeviceMap known_devices_;
183 181
184 GCDSessionMap sessions_; 182 GCDSessionMap sessions_;
185 int last_session_id_; 183 int last_session_id_;
186 184
187 content::BrowserContext* const browser_context_; 185 content::BrowserContext* const browser_context_;
188 186
189 #if defined(ENABLE_WIFI_BOOTSTRAPPING) 187 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
190 scoped_ptr<local_discovery::wifi::WifiManager> wifi_manager_; 188 scoped_ptr<local_discovery::wifi::WifiManager> wifi_manager_;
189 #endif
191 PasswordMap wifi_passwords_; 190 PasswordMap wifi_passwords_;
192 #endif
193 }; 191 };
194 192
195 class GcdPrivateRequest : public local_discovery::PrivetV3Session::Request { 193 class GcdPrivateRequest : public local_discovery::PrivetV3Session::Request {
196 public: 194 public:
197 GcdPrivateRequest(const std::string& api, 195 GcdPrivateRequest(const std::string& api,
198 const base::DictionaryValue& input, 196 const base::DictionaryValue& input,
199 const GcdPrivateAPIImpl::MessageResponseCallback& callback, 197 const GcdPrivateAPIImpl::MessageResponseCallback& callback,
200 GcdPrivateSessionHolder* session_holder); 198 GcdPrivateSessionHolder* session_holder);
201 virtual ~GcdPrivateRequest(); 199 virtual ~GcdPrivateRequest();
202 200
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 382 }
385 383
386 found->second->ConfirmCode(code, callback); 384 found->second->ConfirmCode(code, callback);
387 } 385 }
388 386
389 void GcdPrivateAPIImpl::SendMessage(int session_id, 387 void GcdPrivateAPIImpl::SendMessage(int session_id,
390 const std::string& api, 388 const std::string& api,
391 const base::DictionaryValue& input, 389 const base::DictionaryValue& input,
392 MessageResponseCallback callback) { 390 MessageResponseCallback callback) {
393 const base::DictionaryValue* input_actual = &input; 391 const base::DictionaryValue* input_actual = &input;
394 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
395 scoped_ptr<base::DictionaryValue> input_cloned; 392 scoped_ptr<base::DictionaryValue> input_cloned;
396 393
397 if (api == kPrivatAPISetup) { 394 if (api == kPrivatAPISetup) {
398 const base::DictionaryValue* wifi = NULL; 395 const base::DictionaryValue* wifi = NULL;
399 396
400 if (input.GetDictionary(kPrivetKeyWifi, &wifi)) { 397 if (input.GetDictionary(kPrivetKeyWifi, &wifi)) {
401 std::string ssid; 398 std::string ssid;
402 399
403 if (!wifi->GetString(kPrivetKeySSID, &ssid)) { 400 if (!wifi->GetString(kPrivetKeySSID, &ssid)) {
404 callback.Run(gcd_private::STATUS_SETUPPARSEERROR, 401 callback.Run(gcd_private::STATUS_SETUPPARSEERROR,
(...skipping 11 matching lines...) Expand all
416 base::DictionaryValue()); 413 base::DictionaryValue());
417 return; 414 return;
418 } 415 }
419 416
420 input_cloned.reset(input.DeepCopy()); 417 input_cloned.reset(input.DeepCopy());
421 input_cloned->SetString(kPrivetKeyPassphraseDotted, found->second); 418 input_cloned->SetString(kPrivetKeyPassphraseDotted, found->second);
422 input_actual = input_cloned.get(); 419 input_actual = input_cloned.get();
423 } 420 }
424 } 421 }
425 } 422 }
426 #endif
427 423
428 GCDSessionMap::iterator found = sessions_.find(session_id); 424 GCDSessionMap::iterator found = sessions_.find(session_id);
429 425
430 if (found == sessions_.end()) { 426 if (found == sessions_.end()) {
431 callback.Run(gcd_private::STATUS_UNKNOWNSESSIONERROR, 427 callback.Run(gcd_private::STATUS_UNKNOWNSESSIONERROR,
432 base::DictionaryValue()); 428 base::DictionaryValue());
433 return; 429 return;
434 } 430 }
435 431
436 found->second->SendMessage(api, *input_actual, callback); 432 found->second->SendMessage(api, *input_actual, callback);
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 } 931 }
936 932
937 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() { 933 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() {
938 } 934 }
939 935
940 bool GcdPrivateGetCommandsListFunction::RunAsync() { 936 bool GcdPrivateGetCommandsListFunction::RunAsync() {
941 return false; 937 return false;
942 } 938 }
943 939
944 } // namespace extensions 940 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698