OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/chrome_to_mobile_service.h" | 5 #include "chrome/browser/chrome_to_mobile_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
18 #include "chrome/browser/content_settings/cookie_settings.h" | 18 #include "chrome/browser/content_settings/cookie_settings.h" |
19 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 19 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/signin/token_service.h" | 21 #include "chrome/browser/signin/token_service.h" |
22 #include "chrome/browser/signin/token_service_factory.h" | 22 #include "chrome/browser/signin/token_service_factory.h" |
23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_command_controller.h" |
24 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
25 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 28 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
28 #include "chrome/common/net/gaia/gaia_constants.h" | 29 #include "chrome/common/net/gaia/gaia_constants.h" |
29 #include "chrome/common/net/gaia/gaia_urls.h" | 30 #include "chrome/common/net/gaia/gaia_urls.h" |
30 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" | 31 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" |
31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/notification_details.h" | 33 #include "content/public/browser/notification_details.h" |
33 #include "content/public/browser/notification_source.h" | 34 #include "content/public/browser/notification_source.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 325 } |
325 | 326 |
326 void ChromeToMobileService::SnapshotFileCreated( | 327 void ChromeToMobileService::SnapshotFileCreated( |
327 base::WeakPtr<Observer> observer, | 328 base::WeakPtr<Observer> observer, |
328 const FilePath& path, | 329 const FilePath& path, |
329 bool success) { | 330 bool success) { |
330 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 331 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
331 // Track the set of temporary files to be deleted later. | 332 // Track the set of temporary files to be deleted later. |
332 snapshots_.insert(path); | 333 snapshots_.insert(path); |
333 | 334 |
| 335 // TODO(jam): This is bad and should be replaced with some sort of context. |
334 Browser* browser = browser::FindLastActiveWithProfile(profile_); | 336 Browser* browser = browser::FindLastActiveWithProfile(profile_); |
335 if (success && browser && browser->GetActiveWebContents()) { | 337 if (success && browser && browser->GetActiveWebContents()) { |
336 // Generate the snapshot and have the observer be called back on completion. | 338 // Generate the snapshot and have the observer be called back on completion. |
337 browser->GetActiveWebContents()->GenerateMHTML(path, | 339 browser->GetActiveWebContents()->GenerateMHTML(path, |
338 base::Bind(&Observer::SnapshotGenerated, observer)); | 340 base::Bind(&Observer::SnapshotGenerated, observer)); |
339 } else if (observer.get()) { | 341 } else if (observer.get()) { |
340 // Signal snapshot generation failure. | 342 // Signal snapshot generation failure. |
341 observer->SnapshotGenerated(FilePath(), 0); | 343 observer->SnapshotGenerated(FilePath(), 0); |
342 } | 344 } |
343 } | 345 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 mobile_data->GetString("type", &mobile_type); | 468 mobile_data->GetString("type", &mobile_type); |
467 if (mobile_type.compare(kTypeAndroidChromeSnapshot) == 0) | 469 if (mobile_type.compare(kTypeAndroidChromeSnapshot) == 0) |
468 mobiles.push_back(mobile_data->DeepCopy()); | 470 mobiles.push_back(mobile_data->DeepCopy()); |
469 } | 471 } |
470 } | 472 } |
471 mobiles_ = mobiles.Pass(); | 473 mobiles_ = mobiles.Pass(); |
472 | 474 |
473 if (!mobiles_.empty()) | 475 if (!mobiles_.empty()) |
474 LogMetric(DEVICES_AVAILABLE); | 476 LogMetric(DEVICES_AVAILABLE); |
475 | 477 |
| 478 // TODO(jam): This is bad and should be replaced with some sort of context. |
476 Browser* browser = browser::FindLastActiveWithProfile(profile_); | 479 Browser* browser = browser::FindLastActiveWithProfile(profile_); |
477 if (browser && browser->command_updater()) | 480 if (browser) { |
478 browser->command_updater()->UpdateCommandEnabled( | 481 browser->command_controller()->SendToMobileStateChanged( |
479 IDC_CHROME_TO_MOBILE_PAGE, !mobiles_.empty()); | 482 !mobiles_.empty()); |
| 483 } |
480 } | 484 } |
481 } | 485 } |
482 | 486 |
483 void ChromeToMobileService::HandleSubmitResponse( | 487 void ChromeToMobileService::HandleSubmitResponse( |
484 const net::URLFetcher* source) { | 488 const net::URLFetcher* source) { |
485 // Get the observer for this response; bail if there is none or it is NULL. | 489 // Get the observer for this response; bail if there is none or it is NULL. |
486 RequestObserverMap::iterator i = request_observer_map_.find(source); | 490 RequestObserverMap::iterator i = request_observer_map_.find(source); |
487 if (i == request_observer_map_.end()) | 491 if (i == request_observer_map_.end()) |
488 return; | 492 return; |
489 base::WeakPtr<Observer> observer = i->second; | 493 base::WeakPtr<Observer> observer = i->second; |
(...skipping 20 matching lines...) Expand all Loading... |
510 | 514 |
511 // Ensure a second response is not sent after reporting failure below. | 515 // Ensure a second response is not sent after reporting failure below. |
512 request_observer_map_.erase(other); | 516 request_observer_map_.erase(other); |
513 break; | 517 break; |
514 } | 518 } |
515 } | 519 } |
516 | 520 |
517 LogMetric(success ? SEND_SUCCESS : SEND_ERROR); | 521 LogMetric(success ? SEND_SUCCESS : SEND_ERROR); |
518 observer->OnSendComplete(success); | 522 observer->OnSendComplete(success); |
519 } | 523 } |
OLD | NEW |