Chromium Code Reviews| 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 save (it has | |
|
Dmitry Titov
2015/06/15 21:55:42
save -> saved
fgorski
2015/06/16 15:18:38
Done.
| |
| 22 // URL, title and the whole page content at it's disposal). For that it should | |
| 23 // be also configured with the path where the archives are stored. | |
| 24 // | |
| 25 // Archiver should be able archive multiple pages in parallel, as these are | |
|
Dmitry Titov
2015/06/15 21:55:42
able -> able to
fgorski
2015/06/16 15:18:38
Done.
| |
| 26 // asynchronous calls carried out by some other component. | |
| 27 // | |
| 28 // If archiver get two consecutive requests to archive the same page (may be run | |
|
Dmitry Titov
2015/06/15 21:55:42
get -> gets
fgorski
2015/06/16 15:18:38
Done.
| |
| 29 // in parallel) it can generate 2 different names for files and save the same | |
| 30 // page separately, as if these were 2 completely unrelated pages. It is up to | |
| 31 // the caller (e.g. OfflinePageModel) to make sure that situation like that does | |
| 32 // not happen. | |
| 33 // | |
| 34 // If the page is not completely loaded, it is up to the implemetnation of the | |
|
Dmitry Titov
2015/06/15 21:55:42
type: implemetnation
fgorski
2015/06/16 15:18:38
Done.
| |
| 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 uses sees). | |
|
Dmitry Titov
2015/06/15 21:55:42
uses -> user
fgorski
2015/06/16 15:18:38
Done.
| |
| 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 ArchiveError { | |
| 58 ERROR_UNKNOWN, // Don't know what went wrong. | |
| 59 ERROR_DEVICE_FULL, // Cannot save the archive - device is full. | |
| 60 ERROR_CANCELLED, // Caller cancelled the request. | |
| 61 ERROR_CONTENT_UNAVAILABLE, // Content to archive is not available. | |
| 62 }; | |
| 63 | |
| 64 // Interface of the clients that requests to archive pages. | |
| 65 class Client { | |
| 66 public: | |
| 67 virtual ~Client() {} | |
| 68 | |
| 69 // Callback called by the archiver upon successful creation of the archive. | |
| 70 virtual void OnCreateArchiveSuccess(Request* request, | |
|
Dmitry Titov
2015/06/15 22:30:03
Additional comment: consider merging both callback
fgorski
2015/06/16 15:18:38
Done.
| |
| 71 const base::FilePath& file_path) = 0; | |
| 72 // Callback called by the archiver when it fails to create the archive. | |
| 73 virtual void OnCreateArchiveFailure(Request* request, | |
| 74 ArchiveError error) = 0; | |
| 75 }; | |
| 76 | |
| 77 virtual ~OfflinePageArchiver() {} | |
| 78 | |
| 79 // Starts creating the archive. Will pass result by calling methods on the | |
| 80 // passed in client. Caller owns the returned request object. | |
| 81 // If request is deleted during the archiving, the callback will not be | |
| 82 // invoked. The archive might however be created. | |
| 83 virtual scoped_ptr<Request> CreateArchive(const GURL& url, | |
| 84 Client* client) = 0; | |
| 85 }; | |
| 86 | |
| 87 } // namespace offline_pages | |
| 88 | |
| 89 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_ARCHIVER_H_ | |
| OLD | NEW |