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

Unified Diff: chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_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_fetcher.h
diff --git a/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_fetcher.h b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_fetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..3da11abb5bcf8741f2f44514ef7f4b3934a44e7e
--- /dev/null
+++ b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_fetcher.h
@@ -0,0 +1,111 @@
+// 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_FETCHER_H_
+#define CHROME_BROWSER_CHROME_TO_MOBILE_RECEIVE_CHROME_TO_MOBILE_SNAPSHOTS_FETCHER_H_
+
+#include <set>
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/threading/non_thread_safe.h"
+#include "chrome/browser/chrome_to_mobile/common/cloud_print_request.h"
+#include "googleurl/src/gurl.h"
+
+namespace cloud_print {
+class CloudPrintAuthDelegate;
+}
+
+namespace net {
+class URLRequestContextGetter;
+} // namespace net
+
+namespace chrome_to_mobile_receive {
+
+// Snapshots in chrome_to_mobile feature aim to provide a convenient access on
+// mobile devices to webpages seen in chrome desktop. A snapshot of a web page
+// contains the url of this web page and an optional offline copy of that web
+// page.
+//
+// The data of a snapshot are sent in one or two print jobs:
+// - a print job that contains the webpage url that generates the snapshot,
+// referred to as 'url job', and
+// - (optional) a print job that contains the information on an offline copy of
+// the webpage at this url, referred to as 'offline data job'.
+//
+// This class declares the API to fetch all the pending snapshots. To use
+// it, create a fetcher with an object of |Consumer|, which will be called back
+// when the status of snapshot fetching changes, and call |fetcher->Fetch()|.
+//
+// The following is guaranteed.
+//
+// For each |std::string| |str|, if
+// |consumer->OnSnapshotUrlFetched()| is invoked at time |t| with parameters
+// |snapshot_id = str| and |is_offline_data_expected|, then either
+// !|is_offline_data_expected| or |consumer->OnSnapshotDataDownloadComplete()|
+// is invoked at time |t'| > |t|.
+//
+// No callback after the |fetcher| is destroyed.
+// Note the above condition is still guaranteed in this case and if
+// |consumer->OnSnapshotDataDownloadComplete()| has not been called and an
+// offline data is expected when |fetcher| is destroyed,
+// |consumer->OnSnapshotDataDownloadComplete()| will be invoked with
+// !|success|.
+//
+// Method |fetcher->Fetch()| can be called multiple times to fetch newly
+// arriving jobs.
+//
+// This class is not thread safe; |fetcher->Fetch()| should be called in the
+// same thread where |fetcher| is constructed. The callbacks will also be called
+// in the thread where |fetcher| is constructed.
+class ChromeToMobileSnapshotsFetcher : public base::NonThreadSafe {
+ public:
+ class Consumer {
+ public:
+ Consumer();
+ virtual ~Consumer();
+
+ // Called when the original url of a snapshot is available.
+ virtual void OnSnapshotUrlFetched(const std::string& snapshot_id,
+ const std::string& original_url,
+ const std::string& title,
+ const bool& is_offline_data_expected,
+ const std::string& create_time) = 0;
+ // Called when the download of the offline data of a snapshot completes.
+ virtual void OnSnapshotDataDownloadComplete(
+ const std::string& snapshot_id,
+ const bool& success,
+ const std::string& data_mime_type,
+ const std::string& data) = 0;
+ // This method is called by |ChromeToMobileSnapshotsFetcher| when it
+ // finishes processing all the |Fetch()| invocations. Once this method is
+ // called, no |OnSnapshotUrlFetched()| nor
+ // |OnSnapshotDataDownloadComplete()| will be called before
+ // |fetcher->Fetch()| is called again.
+ virtual void OnSnapshotsFetchComplete(
+ ChromeToMobileSnapshotsFetcher * source) = 0;
+ };
+
+ ChromeToMobileSnapshotsFetcher();
+ virtual ~ChromeToMobileSnapshotsFetcher();
+
+ // Creates a fetcher to fetch pending snapshots sent to the printer identified
+ // by |printer_id| on cloud print server |cloud_print_server_url|. |consumer|
+ // will be called back when snapshot fetch status changes.
+ static ChromeToMobileSnapshotsFetcher* Create(
+ const GURL& cloud_print_server_url,
+ const std::string& printer_id,
+ const chrome_to_mobile::CloudPrintRequest::Settings& settings,
+ Consumer* consumer);
+ virtual void Fetch() = 0;
+ virtual bool HasCloudPrintAuthError() const = 0;
+ virtual bool HasOAuth2AccessTokenFailure() const = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ChromeToMobileSnapshotsFetcher);
+};
+
+} // namespace chrome_to_mobile_receive
+
+#endif // CHROME_BROWSER_CHROME_TO_MOBILE_RECEIVE_CHROME_TO_MOBILE_SNAPSHOTS_FETCHER_H_

Powered by Google App Engine
This is Rietveld 408576698