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

Unified Diff: chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_polling_fetcher.h

Issue 11038063: Support chrome_to_mobile job receiving Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix format Created 8 years, 1 month 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/receive/chrome_to_mobile_snapshots_polling_fetcher.h
diff --git a/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_polling_fetcher.h b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_polling_fetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..500697c7b69511bcf7a5b393f0d2a438482a7a7c
--- /dev/null
+++ b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_polling_fetcher.h
@@ -0,0 +1,114 @@
+// Copyright 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_RECEIVE_CHROME_TO_MOBILE_SNAPSHOTS_POLLING_FETCHER_H_
+#define CHROME_BROWSER_CHROME_TO_MOBILE_RECEIVE_CHROME_TO_MOBILE_SNAPSHOTS_POLLING_FETCHER_H_
+
+#include <map>
+#include <string>
+
+#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/timer.h"
+#include "chrome/browser/chrome_to_mobile/common/cloud_print_request.h"
+#include "chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_fetcher.h"
+#include "googleurl/src/gurl.h"
+#include "net/url_request/url_request_context_getter.h"
+
+namespace base {
+class ListValue;
+} // namespace base
+
+namespace chrome_to_mobile_receive {
+
+// This class implements |ChromeToMobileSnapshotsFetcher| by polling the cloud
+// print servier for offline copies when they are expected. Such an
+// implementation can be used for iOS devices, where a notification will be sent
+// to the targeted iOS device only when a url job arrives at the cloud print
+// server.
+class ChromeToMobileSnapshotsPollingFetcher
+ : public ChromeToMobileSnapshotsFetcher,
+ public chrome_to_mobile::CloudPrintRequest::Delegate {
+ public:
+ ChromeToMobileSnapshotsPollingFetcher(
+ const GURL& cloud_print_server_url,
+ const std::string& printer_id,
+ const chrome_to_mobile::CloudPrintRequest::Settings& settings,
+ ChromeToMobileSnapshotsFetcher::Consumer* consumer,
+ int base_polling_interval_in_seconds,
+ int max_polling_interval_in_seconds,
+ int max_polling_number);
+ virtual ~ChromeToMobileSnapshotsPollingFetcher();
+
+ // |ChromeToMobileSnapshotsFetcher|.
+ virtual void Fetch() OVERRIDE;
+ virtual bool HasCloudPrintAuthError() const OVERRIDE;
+ virtual bool HasOAuth2AccessTokenFailure() const OVERRIDE;
+
+ protected:
+ // |CloudPrintRequest::Delegate|
+ virtual void OnRequestComplete(chrome_to_mobile::CloudPrintRequest* source)
+ OVERRIDE;
+
+ private:
+ // Class that represent a snapshot, including both a url job or an (optional)
+ // offline data job.
+ class SnapshotEntry;
+ friend class SnapshotEntry;
+ // Map from snapshot id to the snapshot entry.
+ typedef std::map<std::string, SnapshotEntry*> SnapshotMap;
+
+ // Polls cloud print server for print jobs.
+ void Poll();
+ // Handles cloud print fetch request completion. Returns true if |source| has
+ // been processed in this method.
+ bool HandleFetchComplete(chrome_to_mobile::CloudPrintRequest* source);
+ // Handles cloud print download request completion. Returns true if |source|
+ // has been processed in this method.
+ bool HandleDownloadComplete(chrome_to_mobile::CloudPrintRequest* source);
+ // Handles cloud print delete request completion. Returns true if |source| has
+ // been processed in this method.
+ bool HandleDeleteComplete(chrome_to_mobile::CloudPrintRequest* source);
+
+ // Add entries to |pending_snapshots_| based on the url jobs in |job_list|.
+ void AddPendingSnapshotsFromURLJobs(const base::ListValue* job_list);
+ // Update |pending_snapshots_| based on the offline data jobs in |job_list|.
+ void UpdatePendingSnapshotsWithOfflineDataJobs(
+ const base::ListValue* job_list);
+
+ // Cancels snpshot fetching.
+ void Cancel();
+ // Deletes all pending snapshots and returns if any pending snapshot is
+ // canceled.
+ bool DeletePendingSnapshots();
+
+ // Variables passed in when constructed.
+ const GURL cloud_print_server_url_;
+ const std::string printer_id_;
+ const chrome_to_mobile::CloudPrintRequest::Settings settings_;
+ ChromeToMobileSnapshotsFetcher::Consumer* const consumer_;
+ // One snapshot might consist of two jobs. This implementation polls the cloud
+ // print server for the offline data job for a snapshot if a url job has been
+ // received and an offline data job is expected.
+ // Time interval between polling the cloud print server.
+ int base_polling_interval_in_seconds_;
+ int max_polling_interval_in_seconds_;
+ const int max_polling_number_;
+
+ // Request that fetches pending jobs at the cloud print server.
+ scoped_ptr<chrome_to_mobile::CloudPrintRequest> fetch_request_;
+ // Snapshots that are being fetched.
+ SnapshotMap pending_snapshots_;
+ // Timer used for polling the cloud print server.
+ base::OneShotTimer<ChromeToMobileSnapshotsPollingFetcher> polling_timer_;
+ int polling_number_;
+ bool has_oauth2_token_fetch_failure_;
+ bool has_cloud_print_auth_error_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeToMobileSnapshotsPollingFetcher);
+};
+
+} // namespace chrome_to_mobile_receive
+
+#endif // CHROME_BROWSER_CHROME_TO_MOBILE_RECEIVE_CHROME_TO_MOBILE_SNAPSHOTS_POLLING_FETCHER_H_

Powered by Google App Engine
This is Rietveld 408576698