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

Side by Side Diff: chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc

Issue 137343005: Send multiple queries when DiscoverNewServices is called on a service watcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/webui/local_discovery/local_discovery_ui_handler.h" 5 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS) && \ 49 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS) && \
50 !defined(OS_MACOSX) 50 !defined(OS_MACOSX)
51 #define CLOUD_PRINT_CONNECTOR_UI_AVAILABLE 51 #define CLOUD_PRINT_CONNECTOR_UI_AVAILABLE
52 #endif 52 #endif
53 53
54 namespace local_discovery { 54 namespace local_discovery {
55 55
56 namespace { 56 namespace {
57 const char kPrivetAutomatedClaimURLFormat[] = "%s/confirm?token=%s"; 57 const char kPrivetAutomatedClaimURLFormat[] = "%s/confirm?token=%s";
58 58
59 const int kInitialRequeryTimeSeconds = 1;
60 const int kMaxRequeryTimeSeconds = 2; // Time for last requery
61
62 int g_num_visible = 0; 59 int g_num_visible = 0;
63
64 } // namespace 60 } // namespace
65 61
66 LocalDiscoveryUIHandler::LocalDiscoveryUIHandler() : is_visible_(false) { 62 LocalDiscoveryUIHandler::LocalDiscoveryUIHandler() : is_visible_(false) {
67 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) 63 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
68 #if !defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) 64 #if !defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
69 // On Windows, we need the PDF plugin which is only guaranteed to exist on 65 // On Windows, we need the PDF plugin which is only guaranteed to exist on
70 // Google Chrome builds. Use a command-line switch for Windows non-Google 66 // Google Chrome builds. Use a command-line switch for Windows non-Google
71 // Chrome builds. 67 // Chrome builds.
72 cloud_print_connector_ui_enabled_ = 68 cloud_print_connector_ui_enabled_ =
73 CommandLine::ForCurrentProcess()->HasSwitch( 69 CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (!privet_lister_) { 132 if (!privet_lister_) {
137 service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance(); 133 service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance();
138 privet_lister_.reset(new PrivetDeviceListerImpl( 134 privet_lister_.reset(new PrivetDeviceListerImpl(
139 service_discovery_client_.get(), this)); 135 service_discovery_client_.get(), this));
140 privet_http_factory_ = 136 privet_http_factory_ =
141 PrivetHTTPAsynchronousFactory::CreateInstance( 137 PrivetHTTPAsynchronousFactory::CreateInstance(
142 service_discovery_client_.get(), profile->GetRequestContext()); 138 service_discovery_client_.get(), profile->GetRequestContext());
143 } 139 }
144 140
145 privet_lister_->Start(); 141 privet_lister_->Start();
146 SendQuery(kInitialRequeryTimeSeconds); 142 privet_lister_->DiscoverNewDevices(false);
147 143
148 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) 144 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
149 StartCloudPrintConnector(); 145 StartCloudPrintConnector();
150 #endif 146 #endif
151 147
152 CheckUserLoggedIn(); 148 CheckUserLoggedIn();
153 149
154 notification_registrar_.RemoveAll(); 150 notification_registrar_.RemoveAll();
155 notification_registrar_.Add(this, 151 notification_registrar_.Add(this,
156 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 152 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 device_descriptions_.erase(name); 372 device_descriptions_.erase(name);
377 scoped_ptr<base::Value> null_value(base::Value::CreateNullValue()); 373 scoped_ptr<base::Value> null_value(base::Value::CreateNullValue());
378 base::StringValue name_value(name); 374 base::StringValue name_value(name);
379 375
380 web_ui()->CallJavascriptFunction("local_discovery.onUnregisteredDeviceUpdate", 376 web_ui()->CallJavascriptFunction("local_discovery.onUnregisteredDeviceUpdate",
381 name_value, *null_value); 377 name_value, *null_value);
382 } 378 }
383 379
384 void LocalDiscoveryUIHandler::DeviceCacheFlushed() { 380 void LocalDiscoveryUIHandler::DeviceCacheFlushed() {
385 web_ui()->CallJavascriptFunction("local_discovery.onDeviceCacheFlushed"); 381 web_ui()->CallJavascriptFunction("local_discovery.onDeviceCacheFlushed");
386 SendQuery(kInitialRequeryTimeSeconds); 382 privet_lister_->DiscoverNewDevices(false);
387 } 383 }
388 384
389 void LocalDiscoveryUIHandler::OnCloudPrintPrinterListReady() { 385 void LocalDiscoveryUIHandler::OnCloudPrintPrinterListReady() {
390 base::ListValue printer_object_list; 386 base::ListValue printer_object_list;
391 std::set<std::string> local_ids; 387 std::set<std::string> local_ids;
392 388
393 for (DeviceDescriptionMap::iterator i = device_descriptions_.begin(); 389 for (DeviceDescriptionMap::iterator i = device_descriptions_.begin();
394 i != device_descriptions_.end(); 390 i != device_descriptions_.end();
395 i++) { 391 i++) {
396 std::string device_id = i->second.id; 392 std::string device_id = i->second.id;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 495
500 return return_value.Pass(); 496 return return_value.Pass();
501 } 497 }
502 498
503 void LocalDiscoveryUIHandler::CheckUserLoggedIn() { 499 void LocalDiscoveryUIHandler::CheckUserLoggedIn() {
504 base::FundamentalValue logged_in_value(!GetSyncAccount().empty()); 500 base::FundamentalValue logged_in_value(!GetSyncAccount().empty());
505 web_ui()->CallJavascriptFunction("local_discovery.setUserLoggedIn", 501 web_ui()->CallJavascriptFunction("local_discovery.setUserLoggedIn",
506 logged_in_value); 502 logged_in_value);
507 } 503 }
508 504
509 void LocalDiscoveryUIHandler::ScheduleQuery(int timeout_seconds) {
510 if (timeout_seconds <= kMaxRequeryTimeSeconds) {
511 requery_callback_.Reset(base::Bind(&LocalDiscoveryUIHandler::SendQuery,
512 base::Unretained(this),
513 timeout_seconds * 2));
514
515 base::MessageLoop::current()->PostDelayedTask(
516 FROM_HERE,
517 requery_callback_.callback(),
518 base::TimeDelta::FromSeconds(timeout_seconds));
519 }
520 }
521
522 void LocalDiscoveryUIHandler::SendQuery(int next_timeout_seconds) {
523 privet_lister_->DiscoverNewDevices(false);
524 ScheduleQuery(next_timeout_seconds);
525 }
526
527 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) 505 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
528 void LocalDiscoveryUIHandler::StartCloudPrintConnector() { 506 void LocalDiscoveryUIHandler::StartCloudPrintConnector() {
529 Profile* profile = Profile::FromWebUI(web_ui()); 507 Profile* profile = Profile::FromWebUI(web_ui());
530 508
531 base::Closure cloud_print_callback = base::Bind( 509 base::Closure cloud_print_callback = base::Bind(
532 &LocalDiscoveryUIHandler::OnCloudPrintPrefsChanged, 510 &LocalDiscoveryUIHandler::OnCloudPrintPrefsChanged,
533 base::Unretained(this)); 511 base::Unretained(this));
534 512
535 if (cloud_print_connector_email_.GetPrefName().empty()) { 513 if (cloud_print_connector_email_.GetPrefName().empty()) {
536 cloud_print_connector_email_.Init( 514 cloud_print_connector_email_.Init(
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 } 600 }
623 601
624 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() { 602 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() {
625 if (cloud_print_connector_ui_enabled_) 603 if (cloud_print_connector_ui_enabled_)
626 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> 604 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))->
627 RefreshStatusFromService(); 605 RefreshStatusFromService();
628 } 606 }
629 #endif // cloud print connector option stuff 607 #endif // cloud print connector option stuff
630 608
631 } // namespace local_discovery 609 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698