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_command_controller.h" |
25 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
26 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
| 27 #include "chrome/browser/ui/browser_tabstrip.h" |
27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 30 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
30 #include "chrome/common/net/gaia/gaia_constants.h" | 31 #include "chrome/common/net/gaia/gaia_constants.h" |
31 #include "chrome/common/net/gaia/gaia_urls.h" | 32 #include "chrome/common/net/gaia/gaia_urls.h" |
32 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" | 33 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" |
33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/notification_details.h" | 35 #include "content/public/browser/notification_details.h" |
35 #include "content/public/browser/notification_source.h" | 36 #include "content/public/browser/notification_source.h" |
36 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 243 |
243 void ChromeToMobileService::SendToMobile(const string16& mobile_id, | 244 void ChromeToMobileService::SendToMobile(const string16& mobile_id, |
244 const FilePath& snapshot, | 245 const FilePath& snapshot, |
245 Browser* browser, | 246 Browser* browser, |
246 base::WeakPtr<Observer> observer) { | 247 base::WeakPtr<Observer> observer) { |
247 LogMetric(SENDING_URL); | 248 LogMetric(SENDING_URL); |
248 | 249 |
249 DCHECK(!access_token_.empty()); | 250 DCHECK(!access_token_.empty()); |
250 RequestData data; | 251 RequestData data; |
251 data.mobile_id = mobile_id; | 252 data.mobile_id = mobile_id; |
252 content::WebContents* web_contents = browser->GetActiveWebContents(); | 253 content::WebContents* web_contents = chrome::GetActiveWebContents(browser); |
253 data.url = web_contents->GetURL(); | 254 data.url = web_contents->GetURL(); |
254 data.title = web_contents->GetTitle(); | 255 data.title = web_contents->GetTitle(); |
255 data.snapshot_path = snapshot; | 256 data.snapshot_path = snapshot; |
256 bool send_snapshot = !snapshot.empty(); | 257 bool send_snapshot = !snapshot.empty(); |
257 data.snapshot_id = send_snapshot ? base::GenerateGUID() : std::string(); | 258 data.snapshot_id = send_snapshot ? base::GenerateGUID() : std::string(); |
258 data.type = send_snapshot ? DELAYED_SNAPSHOT : URL; | 259 data.type = send_snapshot ? DELAYED_SNAPSHOT : URL; |
259 | 260 |
260 net::URLFetcher* submit_url = CreateRequest(data); | 261 net::URLFetcher* submit_url = CreateRequest(data); |
261 request_observer_map_[submit_url] = observer; | 262 request_observer_map_[submit_url] = observer; |
262 submit_url->Start(); | 263 submit_url->Start(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 void ChromeToMobileService::SnapshotFileCreated( | 331 void ChromeToMobileService::SnapshotFileCreated( |
331 base::WeakPtr<Observer> observer, | 332 base::WeakPtr<Observer> observer, |
332 SessionID::id_type browser_id, | 333 SessionID::id_type browser_id, |
333 const FilePath& path, | 334 const FilePath& path, |
334 bool success) { | 335 bool success) { |
335 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 336 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
336 // Track the set of temporary files to be deleted later. | 337 // Track the set of temporary files to be deleted later. |
337 snapshots_.insert(path); | 338 snapshots_.insert(path); |
338 | 339 |
339 Browser* browser = browser::FindBrowserWithID(browser_id); | 340 Browser* browser = browser::FindBrowserWithID(browser_id); |
340 if (success && browser && browser->GetActiveWebContents()) { | 341 if (success && browser && chrome::GetActiveWebContents(browser)) { |
341 // Generate the snapshot and have the observer be called back on completion. | 342 // Generate the snapshot and have the observer be called back on completion. |
342 browser->GetActiveWebContents()->GenerateMHTML(path, | 343 chrome::GetActiveWebContents(browser)->GenerateMHTML(path, |
343 base::Bind(&Observer::SnapshotGenerated, observer)); | 344 base::Bind(&Observer::SnapshotGenerated, observer)); |
344 } else if (observer.get()) { | 345 } else if (observer.get()) { |
345 // Signal snapshot generation failure. | 346 // Signal snapshot generation failure. |
346 observer->SnapshotGenerated(FilePath(), 0); | 347 observer->SnapshotGenerated(FilePath(), 0); |
347 } | 348 } |
348 } | 349 } |
349 | 350 |
350 net::URLFetcher* ChromeToMobileService::CreateRequest( | 351 net::URLFetcher* ChromeToMobileService::CreateRequest( |
351 const RequestData& data) { | 352 const RequestData& data) { |
352 bool get = data.type != SNAPSHOT; | 353 bool get = data.type != SNAPSHOT; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 519 |
519 // Ensure a second response is not sent after reporting failure below. | 520 // Ensure a second response is not sent after reporting failure below. |
520 request_observer_map_.erase(other); | 521 request_observer_map_.erase(other); |
521 break; | 522 break; |
522 } | 523 } |
523 } | 524 } |
524 | 525 |
525 LogMetric(success ? SEND_SUCCESS : SEND_ERROR); | 526 LogMetric(success ? SEND_SUCCESS : SEND_ERROR); |
526 observer->OnSendComplete(success); | 527 observer->OnSendComplete(success); |
527 } | 528 } |
OLD | NEW |