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

Unified 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: Put shared CloudPrint consts/helpers in chrome/common/; use CloudPrintURL. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chrome_to_mobile_service.h
diff --git a/chrome/browser/chrome_to_mobile_service.h b/chrome/browser/chrome_to_mobile_service.h
new file mode 100755
index 0000000000000000000000000000000000000000..5a5c2a6ec5c436cbb9dd01f19a13b44863790a9e
--- /dev/null
+++ b/chrome/browser/chrome_to_mobile_service.h
@@ -0,0 +1,111 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_
+#define CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_
+#pragma once
+
+#include <map>
+#include <vector>
+
+#include "base/file_util.h"
+#include "base/memory/weak_ptr.h"
+#include "base/string16.h"
+#include "base/timer.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
+#include "chrome/common/net/gaia/oauth2_access_token_consumer.h"
+#include "content/public/common/url_fetcher_delegate.h"
+#include "googleurl/src/gurl.h"
+
+class OAuth2AccessTokenFetcher;
+class CloudPrintURL;
+class Profile;
+
+namespace internal {
+
+enum JobType {
+ URL,
+ DELAYED_SNAPSHOT,
+ SNAPSHOT,
+};
+
+struct SubmitData {
+ SubmitData();
+ ~SubmitData();
+
+ string16 mobile_id;
+ GURL url;
+ string16 title;
+ FilePath snapshot_path;
+ std::string snapshot_id;
+ JobType job_type;
+};
+
+} // namespace internal
+
+// ChromeToMobileService connects to the Cloud Print server to enumerate
+// compatible mobiles owned by its profile and send URLs and MHTML snapshots.
+// The mobile list updates regularly, and explicitly by RequestMobileListUpdate.
+class ChromeToMobileService : public ProfileKeyedService,
+ public content::URLFetcherDelegate,
+ public OAuth2AccessTokenConsumer {
+ public:
+ class Observer {
+ public:
+ virtual void OnSendComplete(bool success) = 0;
+ };
+
+ explicit ChromeToMobileService(Profile* profile);
+ virtual ~ChromeToMobileService();
+
+ // content::URLFetcherDelegate methods.
+ virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
+
+ // OAuth2AccessTokenConsumer methods.
+ virtual void OnGetTokenSuccess(const std::string& access_token) OVERRIDE;
+ virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE;
+
+ // Get the list of mobile devices.
+ const std::vector<base::DictionaryValue*>& mobiles() { return mobiles_; }
+
+ // Request an updated mobile device list, request auth first if needed.
+ void RequestMobileListUpdate();
+
+ // Send data to a mobile device; send and then delete valid MHTML |snapshot|s.
+ // Returns the URL or snapshot URLFetcher request for checking status.
+ void SendToMobile(const string16& printer_id,
+ const GURL& url,
+ const string16& title,
+ const FilePath& snapshot,
+ base::WeakPtr<Observer> observer);
+
+ private:
+ // Utility function to create URLFetcher requests.
+ content::URLFetcher* CreateRequest(const internal::SubmitData& data);
+
+ void RequestAuth();
+ void RequestSearch();
+
+ void HandleSearchResponse();
+ void HandleSubmitResponse(const content::URLFetcher* source);
+
+ Profile* profile_;
+ scoped_ptr<CloudPrintURL> cloud_print_url_;
+ std::string oauth2_token_;
+ std::vector<base::DictionaryValue*> mobiles_;
+
+ // Map URLFetchers to observers for reporting OnSendComplete.
+ typedef std::map<const content::URLFetcher*, base::WeakPtr<Observer> >
+ RequestObserverMap;
+ RequestObserverMap request_observer_map_;
+
+ // The currently pending URLFetcther requests, and a timer for retrying.
+ scoped_ptr<OAuth2AccessTokenFetcher> oauth2_request_;
+ scoped_ptr<content::URLFetcher> search_request_;
+ base::OneShotTimer<ChromeToMobileService> request_timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeToMobileService);
+};
+
+#endif // CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698