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

Side by Side Diff: chrome/browser/download/save_package.h

Issue 6374009: Get rid of a few more interfaces from RenderViewHostDelegate that aren't need... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/download/save_package.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ 5 #ifndef CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_
6 #define CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ 6 #define CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/hash_tables.h" 16 #include "base/hash_tables.h"
17 #include "base/ref_counted.h" 17 #include "base/ref_counted.h"
18 #include "base/task.h" 18 #include "base/task.h"
19 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
20 #include "chrome/browser/shell_dialogs.h" 19 #include "chrome/browser/shell_dialogs.h"
20 #include "chrome/browser/tab_contents/web_navigation_observer.h"
21 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
22 22
23 class SaveFileManager; 23 class SaveFileManager;
24 class SaveItem; 24 class SaveItem;
25 class SavePackage; 25 class SavePackage;
26 class DownloadItem; 26 class DownloadItem;
27 class DownloadManager; 27 class DownloadManager;
28 class GURL; 28 class GURL;
29 class MessageLoop; 29 class MessageLoop;
30 class PrefService; 30 class PrefService;
(...skipping 16 matching lines...) Expand all
47 // file regardless internal sub resources and sub frames. 47 // file regardless internal sub resources and sub frames.
48 // Saving page as complete-html page means we save not only the main html file 48 // Saving page as complete-html page means we save not only the main html file
49 // the user told it to save but also a directory for the auxiliary files such 49 // the user told it to save but also a directory for the auxiliary files such
50 // as all sub-frame html files, image files, css files and js files. 50 // as all sub-frame html files, image files, css files and js files.
51 // 51 //
52 // Each page saving job may include one or multiple files which need to be 52 // Each page saving job may include one or multiple files which need to be
53 // saved. Each file is represented by a SaveItem, and all SaveItems are owned 53 // saved. Each file is represented by a SaveItem, and all SaveItems are owned
54 // by the SavePackage. SaveItems are created when a user initiates a page 54 // by the SavePackage. SaveItems are created when a user initiates a page
55 // saving job, and exist for the duration of one tab's life time. 55 // saving job, and exist for the duration of one tab's life time.
56 class SavePackage : public base::RefCountedThreadSafe<SavePackage>, 56 class SavePackage : public base::RefCountedThreadSafe<SavePackage>,
57 public RenderViewHostDelegate::Save, 57 public WebNavigationObserver,
58 public SelectFileDialog::Listener { 58 public SelectFileDialog::Listener {
59 public: 59 public:
60 enum SavePackageType { 60 enum SavePackageType {
61 // The value of the save type before its set by the user. 61 // The value of the save type before its set by the user.
62 SAVE_TYPE_UNKNOWN = -1, 62 SAVE_TYPE_UNKNOWN = -1,
63 // User chose to save only the HTML of the page. 63 // User chose to save only the HTML of the page.
64 SAVE_AS_ONLY_HTML = 0, 64 SAVE_AS_ONLY_HTML = 0,
65 // User chose to save complete-html page. 65 // User chose to save complete-html page.
66 SAVE_AS_COMPLETE_HTML = 1 66 SAVE_AS_COMPLETE_HTML = 1
67 }; 67 };
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 void ShowDownloadInShell(); 121 void ShowDownloadInShell();
122 122
123 bool canceled() const { return user_canceled_ || disk_error_occurred_; } 123 bool canceled() const { return user_canceled_ || disk_error_occurred_; }
124 bool finished() const { return finished_; } 124 bool finished() const { return finished_; }
125 SavePackageType save_type() const { return save_type_; } 125 SavePackageType save_type() const { return save_type_; }
126 int tab_id() const { return tab_id_; } 126 int tab_id() const { return tab_id_; }
127 int id() const { return unique_id_; } 127 int id() const { return unique_id_; }
128 128
129 void GetSaveInfo(); 129 void GetSaveInfo();
130 130
131 // RenderViewHostDelegate::Save ----------------------------------------------
132
133 // Process all of the current page's savable links of subresources, resources
134 // referrers and frames (including the main frame and subframes) from the
135 // render view host.
136 virtual void OnReceivedSavableResourceLinksForCurrentPage(
137 const std::vector<GURL>& resources_list,
138 const std::vector<GURL>& referrers_list,
139 const std::vector<GURL>& frames_list);
140
141 // Process the serialized html content data of a specified web page
142 // gotten from render process.
143 virtual void OnReceivedSerializedHtmlData(const GURL& frame_url,
144 const std::string& data,
145 int32 status);
146
147 // Statics ------------------------------------------------------------------- 131 // Statics -------------------------------------------------------------------
148 132
149 // Used to disable prompting the user for a directory/filename of the saved 133 // Used to disable prompting the user for a directory/filename of the saved
150 // web page. This is available for testing. 134 // web page. This is available for testing.
151 static void SetShouldPromptUser(bool should_prompt); 135 static void SetShouldPromptUser(bool should_prompt);
152 136
153 // Check whether we can do the saving page operation for the specified URL. 137 // Check whether we can do the saving page operation for the specified URL.
154 static bool IsSavableURL(const GURL& url); 138 static bool IsSavableURL(const GURL& url);
155 139
156 // Check whether we can do the saving page operation for the contents which 140 // Check whether we can do the saving page operation for the contents which
(...skipping 15 matching lines...) Expand all
172 ~SavePackage(); 156 ~SavePackage();
173 157
174 // Notes from Init() above applies here as well. 158 // Notes from Init() above applies here as well.
175 void InternalInit(); 159 void InternalInit();
176 160
177 void Stop(); 161 void Stop();
178 void CheckFinish(); 162 void CheckFinish();
179 void SaveNextFile(bool process_all_remainder_items); 163 void SaveNextFile(bool process_all_remainder_items);
180 void DoSavingProcess(); 164 void DoSavingProcess();
181 165
166 // WebNavigationObserver implementation.
167 virtual bool OnMessageReceived(const IPC::Message& message);
168
182 // Create a file name based on the response from the server. 169 // Create a file name based on the response from the server.
183 bool GenerateFileName(const std::string& disposition, 170 bool GenerateFileName(const std::string& disposition,
184 const GURL& url, 171 const GURL& url,
185 bool need_html_ext, 172 bool need_html_ext,
186 FilePath::StringType* generated_name); 173 FilePath::StringType* generated_name);
187 174
188 // Get all savable resource links from current web page, include main 175 // Get all savable resource links from current web page, include main
189 // frame and sub-frame. 176 // frame and sub-frame.
190 void GetAllSavableResourceLinksForCurrentPage(); 177 void GetAllSavableResourceLinksForCurrentPage();
191 // Get html data by serializing all frames of current page with lists 178 // Get html data by serializing all frames of current page with lists
192 // which contain all resource links that have local copy. 179 // which contain all resource links that have local copy.
193 void GetSerializedHtmlDataForCurrentPageWithLocalLinks(); 180 void GetSerializedHtmlDataForCurrentPageWithLocalLinks();
194 181
195 SaveItem* LookupItemInProcessBySaveId(int32 save_id); 182 SaveItem* LookupItemInProcessBySaveId(int32 save_id);
196 void PutInProgressItemToSavedMap(SaveItem* save_item); 183 void PutInProgressItemToSavedMap(SaveItem* save_item);
197 184
198 // Retrieves the URL to be saved from tab_contents_ variable. 185 // Retrieves the URL to be saved from tab_contents_ variable.
199 GURL GetUrlToBeSaved(); 186 GURL GetUrlToBeSaved();
200 187
201 void CreateDirectoryOnFileThread(const FilePath& website_save_dir, 188 void CreateDirectoryOnFileThread(const FilePath& website_save_dir,
202 const FilePath& download_save_dir, 189 const FilePath& download_save_dir,
203 const std::string& mime_type); 190 const std::string& mime_type);
204 void ContinueGetSaveInfo(const FilePath& suggested_path, 191 void ContinueGetSaveInfo(const FilePath& suggested_path,
205 bool can_save_as_complete); 192 bool can_save_as_complete);
206 void ContinueSave(const FilePath& final_name, int index); 193 void ContinueSave(const FilePath& final_name, int index);
207 194
195 void OnReceivedSavableResourceLinksForCurrentPage(
196 const std::vector<GURL>& resources_list,
197 const std::vector<GURL>& referrers_list,
198 const std::vector<GURL>& frames_list);
199
200 void OnReceivedSerializedHtmlData(const GURL& frame_url,
201 const std::string& data,
202 int32 status);
203
208 204
209 typedef base::hash_map<std::string, SaveItem*> SaveUrlItemMap; 205 typedef base::hash_map<std::string, SaveItem*> SaveUrlItemMap;
210 // in_progress_items_ is map of all saving job in in-progress state. 206 // in_progress_items_ is map of all saving job in in-progress state.
211 SaveUrlItemMap in_progress_items_; 207 SaveUrlItemMap in_progress_items_;
212 // saved_failed_items_ is map of all saving job which are failed. 208 // saved_failed_items_ is map of all saving job which are failed.
213 SaveUrlItemMap saved_failed_items_; 209 SaveUrlItemMap saved_failed_items_;
214 210
215 // The number of in process SaveItems. 211 // The number of in process SaveItems.
216 int in_process_count() const { 212 int in_process_count() const {
217 return static_cast<int>(in_progress_items_.size()); 213 return static_cast<int>(in_progress_items_.size());
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 311
316 friend class SavePackageTest; 312 friend class SavePackageTest;
317 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); 313 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames);
318 314
319 ScopedRunnableMethodFactory<SavePackage> method_factory_; 315 ScopedRunnableMethodFactory<SavePackage> method_factory_;
320 316
321 DISALLOW_COPY_AND_ASSIGN(SavePackage); 317 DISALLOW_COPY_AND_ASSIGN(SavePackage);
322 }; 318 };
323 319
324 #endif // CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ 320 #endif // CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/save_package.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698