| 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/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
| 17 #include "chrome/browser/content_settings/cookie_settings.h" | 17 #include "chrome/browser/content_settings/cookie_settings.h" |
| 18 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 18 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/signin/token_service.h" | 20 #include "chrome/browser/signin/token_service.h" |
| 21 #include "chrome/browser/signin/token_service_factory.h" | 21 #include "chrome/browser/signin/token_service_factory.h" |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
| 24 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 26 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
| 27 #include "chrome/common/guid.h" | 27 #include "chrome/common/guid.h" |
| 28 #include "chrome/common/net/gaia/gaia_constants.h" | 28 #include "chrome/common/net/gaia/gaia_constants.h" |
| 29 #include "chrome/common/net/gaia/gaia_urls.h" | 29 #include "chrome/common/net/gaia/gaia_urls.h" |
| 30 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" | 30 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" |
| 31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/notification_details.h" | 32 #include "content/public/browser/notification_details.h" |
| 33 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 void ChromeToMobileService::SendToMobile(const string16& mobile_id, | 239 void ChromeToMobileService::SendToMobile(const string16& mobile_id, |
| 240 const FilePath& snapshot, | 240 const FilePath& snapshot, |
| 241 base::WeakPtr<Observer> observer) { | 241 base::WeakPtr<Observer> observer) { |
| 242 LogMetric(SENDING_URL); | 242 LogMetric(SENDING_URL); |
| 243 | 243 |
| 244 DCHECK(!access_token_.empty()); | 244 DCHECK(!access_token_.empty()); |
| 245 RequestData data; | 245 RequestData data; |
| 246 data.mobile_id = mobile_id; | 246 data.mobile_id = mobile_id; |
| 247 content::WebContents* web_contents = | 247 content::WebContents* web_contents = |
| 248 BrowserList::GetLastActiveWithProfile(profile_)->GetSelectedWebContents(); | 248 browser::FindLastActiveWithProfile(profile_)->GetSelectedWebContents(); |
| 249 data.url = web_contents->GetURL(); | 249 data.url = web_contents->GetURL(); |
| 250 data.title = web_contents->GetTitle(); | 250 data.title = web_contents->GetTitle(); |
| 251 data.snapshot_path = snapshot; | 251 data.snapshot_path = snapshot; |
| 252 bool send_snapshot = !snapshot.empty(); | 252 bool send_snapshot = !snapshot.empty(); |
| 253 data.snapshot_id = send_snapshot ? guid::GenerateGUID() : std::string(); | 253 data.snapshot_id = send_snapshot ? guid::GenerateGUID() : std::string(); |
| 254 data.type = send_snapshot ? DELAYED_SNAPSHOT : URL; | 254 data.type = send_snapshot ? DELAYED_SNAPSHOT : URL; |
| 255 | 255 |
| 256 content::URLFetcher* submit_url = CreateRequest(data); | 256 content::URLFetcher* submit_url = CreateRequest(data); |
| 257 request_observer_map_[submit_url] = observer; | 257 request_observer_map_[submit_url] = observer; |
| 258 submit_url->Start(); | 258 submit_url->Start(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 324 } |
| 325 | 325 |
| 326 void ChromeToMobileService::SnapshotFileCreated( | 326 void ChromeToMobileService::SnapshotFileCreated( |
| 327 base::WeakPtr<Observer> observer, | 327 base::WeakPtr<Observer> observer, |
| 328 const FilePath& path, | 328 const FilePath& path, |
| 329 bool success) { | 329 bool success) { |
| 330 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 330 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 331 // Track the set of temporary files to be deleted later. | 331 // Track the set of temporary files to be deleted later. |
| 332 snapshots_.insert(path); | 332 snapshots_.insert(path); |
| 333 | 333 |
| 334 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 334 Browser* browser = browser::FindLastActiveWithProfile(profile_); |
| 335 if (success && browser && browser->GetSelectedWebContents()) { | 335 if (success && browser && browser->GetSelectedWebContents()) { |
| 336 // Generate the snapshot and have the observer be called back on completion. | 336 // Generate the snapshot and have the observer be called back on completion. |
| 337 browser->GetSelectedWebContents()->GenerateMHTML(path, | 337 browser->GetSelectedWebContents()->GenerateMHTML(path, |
| 338 base::Bind(&Observer::SnapshotGenerated, observer)); | 338 base::Bind(&Observer::SnapshotGenerated, observer)); |
| 339 } else if (observer.get()) { | 339 } else if (observer.get()) { |
| 340 // Signal snapshot generation failure. | 340 // Signal snapshot generation failure. |
| 341 observer->SnapshotGenerated(FilePath(), 0); | 341 observer->SnapshotGenerated(FilePath(), 0); |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 | 344 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 mobile_data->GetString("type", &mobile_type); | 466 mobile_data->GetString("type", &mobile_type); |
| 467 if (mobile_type.compare(kTypeAndroidChromeSnapshot) == 0) | 467 if (mobile_type.compare(kTypeAndroidChromeSnapshot) == 0) |
| 468 mobiles.push_back(mobile_data->DeepCopy()); | 468 mobiles.push_back(mobile_data->DeepCopy()); |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 mobiles_ = mobiles.Pass(); | 471 mobiles_ = mobiles.Pass(); |
| 472 | 472 |
| 473 if (!mobiles_.empty()) | 473 if (!mobiles_.empty()) |
| 474 LogMetric(DEVICES_AVAILABLE); | 474 LogMetric(DEVICES_AVAILABLE); |
| 475 | 475 |
| 476 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 476 Browser* browser = browser::FindLastActiveWithProfile(profile_); |
| 477 if (browser && browser->command_updater()) | 477 if (browser && browser->command_updater()) |
| 478 browser->command_updater()->UpdateCommandEnabled( | 478 browser->command_updater()->UpdateCommandEnabled( |
| 479 IDC_CHROME_TO_MOBILE_PAGE, !mobiles_.empty()); | 479 IDC_CHROME_TO_MOBILE_PAGE, !mobiles_.empty()); |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | 482 |
| 483 void ChromeToMobileService::HandleSubmitResponse( | 483 void ChromeToMobileService::HandleSubmitResponse( |
| 484 const net::URLFetcher* source) { | 484 const net::URLFetcher* source) { |
| 485 // Get the observer for this response; bail if there is none or it is NULL. | 485 // Get the observer for this response; bail if there is none or it is NULL. |
| 486 RequestObserverMap::iterator i = request_observer_map_.find(source); | 486 RequestObserverMap::iterator i = request_observer_map_.find(source); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 510 | 510 |
| 511 // Ensure a second response is not sent after reporting failure below. | 511 // Ensure a second response is not sent after reporting failure below. |
| 512 request_observer_map_.erase(other); | 512 request_observer_map_.erase(other); |
| 513 break; | 513 break; |
| 514 } | 514 } |
| 515 } | 515 } |
| 516 | 516 |
| 517 LogMetric(success ? SEND_SUCCESS : SEND_ERROR); | 517 LogMetric(success ? SEND_SUCCESS : SEND_ERROR); |
| 518 observer->OnSendComplete(success); | 518 observer->OnSendComplete(success); |
| 519 } | 519 } |
| OLD | NEW |