OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_ARCHIVER_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_ARCHIVER_H_ |
| 7 |
| 8 #include "base/files/file_path.h" |
| 9 #include "url/gurl.h" |
| 10 |
| 11 namespace offline_pages { |
| 12 |
| 13 // Interface of a class responsible for creation of the archive for offline use. |
| 14 // |
| 15 // Archiver will be implemented by embedder and may have additional methods that |
| 16 // are not interesting from the perspective of OfflinePageModel. Example of such |
| 17 // extra information or capability is a way to enumerate available WebContents |
| 18 // to find the one that needs to be used to create archive (or to map it to the |
| 19 // URL passed in CreateArchive in some other way). |
| 20 // |
| 21 // Archiver will be responsible for naming the file that is being saved (it has |
| 22 // URL, title and the whole page content at its disposal). For that it should be |
| 23 // also configured with the path where the archives are stored. |
| 24 // |
| 25 // Archiver should be able to archive multiple pages in parallel, as these are |
| 26 // asynchronous calls carried out by some other component. |
| 27 // |
| 28 // If archiver gets two consecutive requests to archive the same page (may be |
| 29 // run in parallel) it can generate 2 different names for files and save the |
| 30 // same page separately, as if these were 2 completely unrelated pages. It is up |
| 31 // to the caller (e.g. OfflinePageModel) to make sure that situation like that |
| 32 // does not happen. |
| 33 // |
| 34 // If the page is not completely loaded, it is up to the implementation of the |
| 35 // archiver whether to respond with ERROR_CONTENT_UNAVAILBLE, wait longer to |
| 36 // actually snapshot a complete page, or snapshot whatever is available at that |
| 37 // point in time (what the user sees). |
| 38 // |
| 39 // TODO(fgorski): Add ability to delete archive. |
| 40 // TODO(fgorski): Add ability to check that archive exists. |
| 41 // TODO(fgorski): Add ability to refresh an existing archive in one step. |
| 42 // TODO(fgorski): Add ability to identify all of the archives in the directory, |
| 43 // to enable to model to reconcile the archives. |
| 44 class OfflinePageArchiver { |
| 45 public: |
| 46 // Represents an in progress request to archive a page. |
| 47 class Request { |
| 48 public: |
| 49 virtual ~Request() {} |
| 50 |
| 51 // Cancels an in progress request to archive a page. |
| 52 virtual void Cancel() = 0; |
| 53 virtual const GURL& url() const = 0; |
| 54 }; |
| 55 |
| 56 // Errors that will be reported when archive creation fails. |
| 57 enum ArchiverResult { |
| 58 SUCCESSFULLY_CREATED, // Archive created successfully. |
| 59 ERROR_UNKNOWN, // Don't know what went wrong. |
| 60 ERROR_DEVICE_FULL, // Cannot save the archive - device is full. |
| 61 ERROR_CANCELLED, // Caller cancelled the request. |
| 62 ERROR_CONTENT_UNAVAILABLE, // Content to archive is not available. |
| 63 }; |
| 64 |
| 65 // Interface of the clients that requests to archive pages. |
| 66 class Client { |
| 67 public: |
| 68 virtual ~Client() {} |
| 69 |
| 70 // Callback called by the archiver when archiver creation is complete. |
| 71 // |result| will indicate SUCCESSFULLY_CREATED upon success, or a specific |
| 72 // error, when it failed. |
| 73 virtual void OnCreateArchiveDone(Request* request, |
| 74 ArchiverResult result, |
| 75 const base::FilePath& file_path) = 0; |
| 76 }; |
| 77 |
| 78 virtual ~OfflinePageArchiver() {} |
| 79 |
| 80 // Starts creating the archive. Will pass result by calling methods on the |
| 81 // passed in client. Caller owns the returned request object. |
| 82 // If request is deleted during the archiving, the callback will not be |
| 83 // invoked. The archive might however be created. |
| 84 virtual scoped_ptr<Request> CreateArchive(const GURL& url, |
| 85 Client* client) = 0; |
| 86 }; |
| 87 |
| 88 } // namespace offline_pages |
| 89 |
| 90 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_ARCHIVER_H_ |
OLD | NEW |