OLD | NEW |
(Empty) | |
| 1 // Copyright 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_RECEIVE_CHROME_TO_MOBILE_SNAPSHOTS_FETCH
ER_H_ |
| 6 #define CHROME_BROWSER_CHROME_TO_MOBILE_RECEIVE_CHROME_TO_MOBILE_SNAPSHOTS_FETCH
ER_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/threading/non_thread_safe.h" |
| 13 #include "chrome/browser/chrome_to_mobile/common/cloud_print_request.h" |
| 14 #include "googleurl/src/gurl.h" |
| 15 |
| 16 namespace cloud_print { |
| 17 class CloudPrintAuthDelegate; |
| 18 } |
| 19 |
| 20 namespace net { |
| 21 class URLRequestContextGetter; |
| 22 } // namespace net |
| 23 |
| 24 namespace chrome_to_mobile_receive { |
| 25 |
| 26 // Snapshots in chrome_to_mobile feature aim to provide a convenient access on |
| 27 // mobile devices to webpages seen in chrome desktop. A snapshot of a web page |
| 28 // contains the url of this web page and an optional offline copy of that web |
| 29 // page. |
| 30 // |
| 31 // The data of a snapshot are sent in one or two print jobs: |
| 32 // - a print job that contains the webpage url that generates the snapshot, |
| 33 // referred to as 'url job', and |
| 34 // - (optional) a print job that contains the information on an offline copy of |
| 35 // the webpage at this url, referred to as 'offline data job'. |
| 36 // |
| 37 // This class declares the API to fetch all the pending snapshots. To use |
| 38 // it, create a fetcher with an object of |Consumer|, which will be called back |
| 39 // when the status of snapshot fetching changes, and call |fetcher->Fetch()|. |
| 40 // |
| 41 // The following is guaranteed. |
| 42 // |
| 43 // For each |std::string| |str|, if |
| 44 // |consumer->OnSnapshotUrlFetched()| is invoked at time |t| with parameters |
| 45 // |snapshot_id = str| and |is_offline_data_expected|, then either |
| 46 // !|is_offline_data_expected| or |consumer->OnSnapshotDataDownloadComplete()| |
| 47 // is invoked at time |t'| > |t|. |
| 48 // |
| 49 // No callback after the |fetcher| is destroyed. |
| 50 // Note the above condition is still guaranteed in this case and if |
| 51 // |consumer->OnSnapshotDataDownloadComplete()| has not been called and an |
| 52 // offline data is expected when |fetcher| is destroyed, |
| 53 // |consumer->OnSnapshotDataDownloadComplete()| will be invoked with |
| 54 // !|success|. |
| 55 // |
| 56 // Method |fetcher->Fetch()| can be called multiple times to fetch newly |
| 57 // arriving jobs. |
| 58 // |
| 59 // This class is not thread safe; |fetcher->Fetch()| should be called in the |
| 60 // same thread where |fetcher| is constructed. The callbacks will also be called |
| 61 // in the thread where |fetcher| is constructed. |
| 62 class ChromeToMobileSnapshotsFetcher : public base::NonThreadSafe { |
| 63 public: |
| 64 class Consumer { |
| 65 public: |
| 66 Consumer(); |
| 67 virtual ~Consumer(); |
| 68 |
| 69 // Called when the original url of a snapshot is available. |
| 70 virtual void OnSnapshotUrlFetched(const std::string& snapshot_id, |
| 71 const std::string& original_url, |
| 72 const std::string& title, |
| 73 const bool& is_offline_data_expected, |
| 74 const std::string& create_time) = 0; |
| 75 // Called when the download of the offline data of a snapshot completes. |
| 76 virtual void OnSnapshotDataDownloadComplete( |
| 77 const std::string& snapshot_id, |
| 78 const bool& success, |
| 79 const std::string& data_mime_type, |
| 80 const std::string& data) = 0; |
| 81 // This method is called by |ChromeToMobileSnapshotsFetcher| when it |
| 82 // finishes processing all the |Fetch()| invocations. Once this method is |
| 83 // called, no |OnSnapshotUrlFetched()| nor |
| 84 // |OnSnapshotDataDownloadComplete()| will be called before |
| 85 // |fetcher->Fetch()| is called again. |
| 86 virtual void OnSnapshotsFetchComplete( |
| 87 ChromeToMobileSnapshotsFetcher * source) = 0; |
| 88 }; |
| 89 |
| 90 ChromeToMobileSnapshotsFetcher(); |
| 91 virtual ~ChromeToMobileSnapshotsFetcher(); |
| 92 |
| 93 // Creates a fetcher to fetch pending snapshots sent to the printer identified |
| 94 // by |printer_id| on cloud print server |cloud_print_server_url|. |consumer| |
| 95 // will be called back when snapshot fetch status changes. |
| 96 static ChromeToMobileSnapshotsFetcher* Create( |
| 97 const GURL& cloud_print_server_url, |
| 98 const std::string& printer_id, |
| 99 const chrome_to_mobile::CloudPrintRequest::Settings& settings, |
| 100 Consumer* consumer); |
| 101 virtual void Fetch() = 0; |
| 102 virtual bool HasCloudPrintAuthError() const = 0; |
| 103 virtual bool HasOAuth2AccessTokenFailure() const = 0; |
| 104 |
| 105 private: |
| 106 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileSnapshotsFetcher); |
| 107 }; |
| 108 |
| 109 } // namespace chrome_to_mobile_receive |
| 110 |
| 111 #endif // CHROME_BROWSER_CHROME_TO_MOBILE_RECEIVE_CHROME_TO_MOBILE_SNAPSHOTS_FE
TCHER_H_ |
OLD | NEW |