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

Side by Side Diff: chrome/browser/chrome_to_mobile_service.h

Issue 9443007: Add Chrome To Mobile Service and Views Page Action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nix animation change, init icon visible, fix mac id test, DCHECK token, etc. Created 8 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_
6 #define CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_
7 #pragma once
8
9 #include <map>
10 #include <vector>
11
12 #include "base/file_util.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/scoped_temp_dir.h"
15 #include "base/string16.h"
16 #include "base/timer.h"
17 #include "chrome/browser/profiles/profile_keyed_service.h"
18 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h"
19 #include "content/public/common/url_fetcher_delegate.h"
20 #include "googleurl/src/gurl.h"
21
22 class OAuth2AccessTokenFetcher;
23 class CloudPrintURL;
24 class Profile;
25
26 // ChromeToMobileService connects to the cloud print service to enumerate
27 // compatible mobiles owned by its profile and send URLs and MHTML snapshots.
28 // The mobile list updates regularly, and explicitly by RequestMobileListUpdate.
29 class ChromeToMobileService : public ProfileKeyedService,
30 public content::URLFetcherDelegate,
31 public OAuth2AccessTokenConsumer {
32 public:
33 class Observer {
34 public:
35 // Called on generation of the page's MHTML snapshot.
36 virtual void SnapshotGenerated(const FilePath& path, int64 bytes) = 0;
37
38 // Called after URLFetcher responses from sending the URL (and snapshot).
39 virtual void OnSendComplete(bool success) = 0;
40 };
41
42 // The URLFetcher request types.
43 enum RequestType {
44 SEARCH,
45 URL,
46 DELAYED_SNAPSHOT,
47 SNAPSHOT,
48 };
49
50 // The aggregated URLFetcher submission data.
51 struct RequestData {
52 RequestData();
53 ~RequestData();
54
55 string16 mobile_id;
56 GURL url;
57 string16 title;
58 FilePath snapshot_path;
59 std::string snapshot_id;
60 RequestType type;
61 };
62
63 explicit ChromeToMobileService(Profile* profile);
64 virtual ~ChromeToMobileService();
65
66 // content::URLFetcherDelegate methods.
67 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
68
69 // OAuth2AccessTokenConsumer methods.
70 virtual void OnGetTokenSuccess(const std::string& access_token) OVERRIDE;
71 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE;
72
73 // Get the list of mobile devices.
74 const std::vector<base::DictionaryValue*>& mobiles() { return mobiles_; }
75
76 // Request an updated mobile device list, request auth first if needed.
77 void RequestMobileListUpdate();
78
79 // Callback with an MHTML snapshot of the profile's selected WebContents.
80 void GenerateSnapshot(base::WeakPtr<Observer> observer);
81
82 // Send the profile's selected WebContents to the specified mobile device.
83 void SendToMobile(const string16& mobile_id,
84 const FilePath& snapshot,
85 base::WeakPtr<Observer> observer);
86
87 private:
88 // Utility function to initialize the ScopedTempDir.
89 void CreateUniqueTempDir();
90
91 // Utility function to create URLFetcher requests.
92 content::URLFetcher* CreateRequest(const RequestData& data);
93
94 void RequestAuth();
95 void RequestSearch();
96
97 void HandleSearchResponse();
98 void HandleSubmitResponse(const content::URLFetcher* source);
99
100 Profile* profile_;
101
102 // A utility class for accessing the cloud print service.
103 scoped_ptr<CloudPrintURL> cloud_print_url_;
104
105 // The list of mobile devices retrieved from the cloud print service.
106 std::vector<base::DictionaryValue*> mobiles_;
107
108 // The temporary directory for MHTML snapshot files.
109 ScopedTempDir temp_dir_;
110
111 // Map URLFetchers to observers for reporting OnSendComplete.
112 typedef std::map<const content::URLFetcher*, base::WeakPtr<Observer> >
113 RequestObserverMap;
114 RequestObserverMap request_observer_map_;
115
116 // The OAuth2 token and retry count.
117 std::string oauth2_token_;
118 size_t oauth2_retry_count_;
119
120 // The pending URL requests.
121 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_request_;
122 scoped_ptr<content::URLFetcher> search_request_;
123
124 // A timer for authentication retries and mobile device list updates.
125 base::OneShotTimer<ChromeToMobileService> request_timer_;
126
127 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileService);
128 };
129
130 #endif // CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698