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

Side by Side Diff: content/browser/download/download_item_impl.h

Issue 12213066: Use base namespace for FilePath in content/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 static const int kMaxAutoResumeAttempts; 46 static const int kMaxAutoResumeAttempts;
47 47
48 // Note that it is the responsibility of the caller to ensure that a 48 // Note that it is the responsibility of the caller to ensure that a
49 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor 49 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor
50 // outlives the DownloadItemImpl. 50 // outlives the DownloadItemImpl.
51 51
52 // Constructing from persistent store: 52 // Constructing from persistent store:
53 // |bound_net_log| is constructed externally for our use. 53 // |bound_net_log| is constructed externally for our use.
54 DownloadItemImpl(DownloadItemImplDelegate* delegate, 54 DownloadItemImpl(DownloadItemImplDelegate* delegate,
55 DownloadId download_id, 55 DownloadId download_id,
56 const FilePath& current_path, 56 const base::FilePath& current_path,
57 const FilePath& target_path, 57 const base::FilePath& target_path,
58 const std::vector<GURL>& url_chain, 58 const std::vector<GURL>& url_chain,
59 const GURL& referrer_url, 59 const GURL& referrer_url,
60 const base::Time& start_time, 60 const base::Time& start_time,
61 const base::Time& end_time, 61 const base::Time& end_time,
62 int64 received_bytes, 62 int64 received_bytes,
63 int64 total_bytes, 63 int64 total_bytes,
64 DownloadItem::DownloadState state, 64 DownloadItem::DownloadState state,
65 DownloadDangerType danger_type, 65 DownloadDangerType danger_type,
66 DownloadInterruptReason interrupt_reason, 66 DownloadInterruptReason interrupt_reason,
67 bool opened, 67 bool opened,
68 const net::BoundNetLog& bound_net_log); 68 const net::BoundNetLog& bound_net_log);
69 69
70 // Constructing for a regular download. 70 // Constructing for a regular download.
71 // |bound_net_log| is constructed externally for our use. 71 // |bound_net_log| is constructed externally for our use.
72 DownloadItemImpl(DownloadItemImplDelegate* delegate, 72 DownloadItemImpl(DownloadItemImplDelegate* delegate,
73 const DownloadCreateInfo& info, 73 const DownloadCreateInfo& info,
74 const net::BoundNetLog& bound_net_log); 74 const net::BoundNetLog& bound_net_log);
75 75
76 // Constructing for the "Save Page As..." feature: 76 // Constructing for the "Save Page As..." feature:
77 // |bound_net_log| is constructed externally for our use. 77 // |bound_net_log| is constructed externally for our use.
78 DownloadItemImpl(DownloadItemImplDelegate* delegate, 78 DownloadItemImpl(DownloadItemImplDelegate* delegate,
79 const FilePath& path, 79 const base::FilePath& path,
80 const GURL& url, 80 const GURL& url,
81 DownloadId download_id, 81 DownloadId download_id,
82 const std::string& mime_type, 82 const std::string& mime_type,
83 const net::BoundNetLog& bound_net_log); 83 const net::BoundNetLog& bound_net_log);
84 84
85 virtual ~DownloadItemImpl(); 85 virtual ~DownloadItemImpl();
86 86
87 // DownloadItem 87 // DownloadItem
88 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; 88 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE;
89 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; 89 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE;
(...skipping 25 matching lines...) Expand all
115 virtual std::string GetSuggestedFilename() const OVERRIDE; 115 virtual std::string GetSuggestedFilename() const OVERRIDE;
116 virtual std::string GetContentDisposition() const OVERRIDE; 116 virtual std::string GetContentDisposition() const OVERRIDE;
117 virtual std::string GetMimeType() const OVERRIDE; 117 virtual std::string GetMimeType() const OVERRIDE;
118 virtual std::string GetOriginalMimeType() const OVERRIDE; 118 virtual std::string GetOriginalMimeType() const OVERRIDE;
119 virtual std::string GetRemoteAddress() const OVERRIDE; 119 virtual std::string GetRemoteAddress() const OVERRIDE;
120 virtual bool HasUserGesture() const OVERRIDE; 120 virtual bool HasUserGesture() const OVERRIDE;
121 virtual PageTransition GetTransitionType() const OVERRIDE; 121 virtual PageTransition GetTransitionType() const OVERRIDE;
122 virtual const std::string& GetLastModifiedTime() const OVERRIDE; 122 virtual const std::string& GetLastModifiedTime() const OVERRIDE;
123 virtual const std::string& GetETag() const OVERRIDE; 123 virtual const std::string& GetETag() const OVERRIDE;
124 virtual bool IsSavePackageDownload() const OVERRIDE; 124 virtual bool IsSavePackageDownload() const OVERRIDE;
125 virtual const FilePath& GetFullPath() const OVERRIDE; 125 virtual const base::FilePath& GetFullPath() const OVERRIDE;
126 virtual const FilePath& GetTargetFilePath() const OVERRIDE; 126 virtual const base::FilePath& GetTargetFilePath() const OVERRIDE;
127 virtual const FilePath& GetForcedFilePath() const OVERRIDE; 127 virtual const base::FilePath& GetForcedFilePath() const OVERRIDE;
128 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; 128 virtual base::FilePath GetUserVerifiedFilePath() const OVERRIDE;
129 virtual FilePath GetFileNameToReportUser() const OVERRIDE; 129 virtual base::FilePath GetFileNameToReportUser() const OVERRIDE;
130 virtual TargetDisposition GetTargetDisposition() const OVERRIDE; 130 virtual TargetDisposition GetTargetDisposition() const OVERRIDE;
131 virtual const std::string& GetHash() const OVERRIDE; 131 virtual const std::string& GetHash() const OVERRIDE;
132 virtual const std::string& GetHashState() const OVERRIDE; 132 virtual const std::string& GetHashState() const OVERRIDE;
133 virtual bool GetFileExternallyRemoved() const OVERRIDE; 133 virtual bool GetFileExternallyRemoved() const OVERRIDE;
134 virtual bool IsDangerous() const OVERRIDE; 134 virtual bool IsDangerous() const OVERRIDE;
135 virtual DownloadDangerType GetDangerType() const OVERRIDE; 135 virtual DownloadDangerType GetDangerType() const OVERRIDE;
136 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE; 136 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE;
137 virtual int64 CurrentSpeed() const OVERRIDE; 137 virtual int64 CurrentSpeed() const OVERRIDE;
138 virtual int PercentComplete() const OVERRIDE; 138 virtual int PercentComplete() const OVERRIDE;
139 virtual bool AllDataSaved() const OVERRIDE; 139 virtual bool AllDataSaved() const OVERRIDE;
140 virtual int64 GetTotalBytes() const OVERRIDE; 140 virtual int64 GetTotalBytes() const OVERRIDE;
141 virtual int64 GetReceivedBytes() const OVERRIDE; 141 virtual int64 GetReceivedBytes() const OVERRIDE;
142 virtual base::Time GetStartTime() const OVERRIDE; 142 virtual base::Time GetStartTime() const OVERRIDE;
143 virtual base::Time GetEndTime() const OVERRIDE; 143 virtual base::Time GetEndTime() const OVERRIDE;
144 virtual bool CanShowInFolder() OVERRIDE; 144 virtual bool CanShowInFolder() OVERRIDE;
145 virtual bool CanOpenDownload() OVERRIDE; 145 virtual bool CanOpenDownload() OVERRIDE;
146 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; 146 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE;
147 virtual bool GetOpenWhenComplete() const OVERRIDE; 147 virtual bool GetOpenWhenComplete() const OVERRIDE;
148 virtual bool GetAutoOpened() OVERRIDE; 148 virtual bool GetAutoOpened() OVERRIDE;
149 virtual bool GetOpened() const OVERRIDE; 149 virtual bool GetOpened() const OVERRIDE;
150 virtual BrowserContext* GetBrowserContext() const OVERRIDE; 150 virtual BrowserContext* GetBrowserContext() const OVERRIDE;
151 virtual WebContents* GetWebContents() const OVERRIDE; 151 virtual WebContents* GetWebContents() const OVERRIDE;
152 virtual void OnContentCheckCompleted(DownloadDangerType danger_type) OVERRIDE; 152 virtual void OnContentCheckCompleted(DownloadDangerType danger_type) OVERRIDE;
153 virtual void SetOpenWhenComplete(bool open) OVERRIDE; 153 virtual void SetOpenWhenComplete(bool open) OVERRIDE;
154 virtual void SetIsTemporary(bool temporary) OVERRIDE; 154 virtual void SetIsTemporary(bool temporary) OVERRIDE;
155 virtual void SetOpened(bool opened) OVERRIDE; 155 virtual void SetOpened(bool opened) OVERRIDE;
156 virtual void SetDisplayName(const FilePath& name) OVERRIDE; 156 virtual void SetDisplayName(const base::FilePath& name) OVERRIDE;
157 virtual std::string DebugString(bool verbose) const OVERRIDE; 157 virtual std::string DebugString(bool verbose) const OVERRIDE;
158 158
159 // All remaining public interfaces virtual to allow for DownloadItemImpl 159 // All remaining public interfaces virtual to allow for DownloadItemImpl
160 // mocks. 160 // mocks.
161 161
162 virtual ResumeMode GetResumeMode() const; 162 virtual ResumeMode GetResumeMode() const;
163 163
164 // State transition operations on regular downloads -------------------------- 164 // State transition operations on regular downloads --------------------------
165 165
166 // Start the download. 166 // Start the download.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 // |download_type| indicates to the net log system what kind of download 254 // |download_type| indicates to the net log system what kind of download
255 // this is. 255 // this is.
256 void Init(bool active, DownloadType download_type); 256 void Init(bool active, DownloadType download_type);
257 257
258 // Called when the target path has been determined. |target_path| is the 258 // Called when the target path has been determined. |target_path| is the
259 // suggested target path. |disposition| indicates how the target path should 259 // suggested target path. |disposition| indicates how the target path should
260 // be used (see TargetDisposition). |danger_type| is the danger level of 260 // be used (see TargetDisposition). |danger_type| is the danger level of
261 // |target_path| as determined by the caller. |intermediate_path| is the path 261 // |target_path| as determined by the caller. |intermediate_path| is the path
262 // to use to store the download until OnDownloadCompleting() is called. 262 // to use to store the download until OnDownloadCompleting() is called.
263 virtual void OnDownloadTargetDetermined( 263 virtual void OnDownloadTargetDetermined(
264 const FilePath& target_path, 264 const base::FilePath& target_path,
265 TargetDisposition disposition, 265 TargetDisposition disposition,
266 DownloadDangerType danger_type, 266 DownloadDangerType danger_type,
267 const FilePath& intermediate_path); 267 const base::FilePath& intermediate_path);
268 268
269 // Callback from file thread when we initialize the DownloadFile. 269 // Callback from file thread when we initialize the DownloadFile.
270 void OnDownloadFileInitialized(DownloadInterruptReason result); 270 void OnDownloadFileInitialized(DownloadInterruptReason result);
271 271
272 void OnDownloadRenamedToIntermediateName( 272 void OnDownloadRenamedToIntermediateName(
273 DownloadInterruptReason reason, const FilePath& full_path); 273 DownloadInterruptReason reason, const base::FilePath& full_path);
274 274
275 // If all pre-requisites have been met, complete download processing, i.e. do 275 // If all pre-requisites have been met, complete download processing, i.e. do
276 // internal cleanup, file rename, and potentially auto-open. (Dangerous 276 // internal cleanup, file rename, and potentially auto-open. (Dangerous
277 // downloads still may block on user acceptance after this point.) 277 // downloads still may block on user acceptance after this point.)
278 void MaybeCompleteDownload(); 278 void MaybeCompleteDownload();
279 279
280 // Called when the download is ready to complete. 280 // Called when the download is ready to complete.
281 // This may perform final rename if necessary and will eventually call 281 // This may perform final rename if necessary and will eventually call
282 // DownloadItem::Completed(). 282 // DownloadItem::Completed().
283 void OnDownloadCompleting(); 283 void OnDownloadCompleting();
284 284
285 void OnDownloadRenamedToFinalName(DownloadInterruptReason reason, 285 void OnDownloadRenamedToFinalName(DownloadInterruptReason reason,
286 const FilePath& full_path); 286 const base::FilePath& full_path);
287 287
288 // Called if the embedder took over opening a download, to indicate that 288 // Called if the embedder took over opening a download, to indicate that
289 // the download has been opened. 289 // the download has been opened.
290 void DelayedDownloadOpened(bool auto_opened); 290 void DelayedDownloadOpened(bool auto_opened);
291 291
292 // Called when the entire download operation (including renaming etc) 292 // Called when the entire download operation (including renaming etc)
293 // is completed. 293 // is completed.
294 void Completed(); 294 void Completed();
295 295
296 // Helper routines ----------------------------------------------------------- 296 // Helper routines -----------------------------------------------------------
297 297
298 // Indicate that an error has occurred on the download. 298 // Indicate that an error has occurred on the download.
299 void Interrupt(DownloadInterruptReason reason); 299 void Interrupt(DownloadInterruptReason reason);
300 300
301 // Cancel the DownloadFile if we have it. 301 // Cancel the DownloadFile if we have it.
302 void CancelDownloadFile(); 302 void CancelDownloadFile();
303 303
304 // Check if a download is ready for completion. The callback provided 304 // Check if a download is ready for completion. The callback provided
305 // may be called at some point in the future if an external entity 305 // may be called at some point in the future if an external entity
306 // state has change s.t. this routine should be checked again. 306 // state has change s.t. this routine should be checked again.
307 bool IsDownloadReadyForCompletion(const base::Closure& state_change_notify); 307 bool IsDownloadReadyForCompletion(const base::Closure& state_change_notify);
308 308
309 // Call to transition state; all state transitions should go through this. 309 // Call to transition state; all state transitions should go through this.
310 void TransitionTo(DownloadInternalState new_state); 310 void TransitionTo(DownloadInternalState new_state);
311 311
312 // Set the |danger_type_| and invoke obserers if necessary. 312 // Set the |danger_type_| and invoke obserers if necessary.
313 void SetDangerType(DownloadDangerType danger_type); 313 void SetDangerType(DownloadDangerType danger_type);
314 314
315 void SetFullPath(const FilePath& new_path); 315 void SetFullPath(const base::FilePath& new_path);
316 316
317 void AutoResumeIfValid(); 317 void AutoResumeIfValid();
318 318
319 static DownloadState InternalToExternalState( 319 static DownloadState InternalToExternalState(
320 DownloadInternalState internal_state); 320 DownloadInternalState internal_state);
321 static DownloadInternalState ExternalToInternalState( 321 static DownloadInternalState ExternalToInternalState(
322 DownloadState external_state); 322 DownloadState external_state);
323 323
324 // Debugging routines -------------------------------------------------------- 324 // Debugging routines --------------------------------------------------------
325 static const char* DebugDownloadStateString(DownloadInternalState state); 325 static const char* DebugDownloadStateString(DownloadInternalState state);
326 static const char* DebugResumeModeString(ResumeMode mode); 326 static const char* DebugResumeModeString(ResumeMode mode);
327 327
328 // Will be false for save package downloads retrieved from the history. 328 // Will be false for save package downloads retrieved from the history.
329 // TODO(rdsmith): Replace with a generalized enum for "download source". 329 // TODO(rdsmith): Replace with a generalized enum for "download source".
330 const bool is_save_package_download_; 330 const bool is_save_package_download_;
331 331
332 // The handle to the request information. Used for operations outside the 332 // The handle to the request information. Used for operations outside the
333 // download system. 333 // download system.
334 scoped_ptr<DownloadRequestHandleInterface> request_handle_; 334 scoped_ptr<DownloadRequestHandleInterface> request_handle_;
335 335
336 // Download ID assigned by DownloadResourceHandler. 336 // Download ID assigned by DownloadResourceHandler.
337 DownloadId download_id_; 337 DownloadId download_id_;
338 338
339 // Display name for the download. If this is empty, then the display name is 339 // Display name for the download. If this is empty, then the display name is
340 // considered to be |target_path_.BaseName()|. 340 // considered to be |target_path_.BaseName()|.
341 FilePath display_name_; 341 base::FilePath display_name_;
342 342
343 // Full path to the downloaded or downloading file. This is the path to the 343 // Full path to the downloaded or downloading file. This is the path to the
344 // physical file, if one exists. The final target path is specified by 344 // physical file, if one exists. The final target path is specified by
345 // |target_path_|. |current_path_| can be empty if the in-progress path hasn't 345 // |target_path_|. |current_path_| can be empty if the in-progress path hasn't
346 // been determined. 346 // been determined.
347 FilePath current_path_; 347 base::FilePath current_path_;
348 348
349 // Target path of an in-progress download. We may be downloading to a 349 // Target path of an in-progress download. We may be downloading to a
350 // temporary or intermediate file (specified by |current_path_|. Once the 350 // temporary or intermediate file (specified by |current_path_|. Once the
351 // download completes, we will rename the file to |target_path_|. 351 // download completes, we will rename the file to |target_path_|.
352 FilePath target_path_; 352 base::FilePath target_path_;
353 353
354 // Whether the target should be overwritten, uniquified or prompted for. 354 // Whether the target should be overwritten, uniquified or prompted for.
355 TargetDisposition target_disposition_; 355 TargetDisposition target_disposition_;
356 356
357 // The chain of redirects that leading up to and including the final URL. 357 // The chain of redirects that leading up to and including the final URL.
358 std::vector<GURL> url_chain_; 358 std::vector<GURL> url_chain_;
359 359
360 // The URL of the page that initiated the download. 360 // The URL of the page that initiated the download.
361 GURL referrer_url_; 361 GURL referrer_url_;
362 362
363 // Filename suggestion from DownloadSaveInfo. It could, among others, be the 363 // Filename suggestion from DownloadSaveInfo. It could, among others, be the
364 // suggested filename in 'download' attribute of an anchor. Details: 364 // suggested filename in 'download' attribute of an anchor. Details:
365 // http://www.whatwg.org/specs/web-apps/current-work/#downloading-hyperlinks 365 // http://www.whatwg.org/specs/web-apps/current-work/#downloading-hyperlinks
366 std::string suggested_filename_; 366 std::string suggested_filename_;
367 367
368 // If non-empty, contains an externally supplied path that should be used as 368 // If non-empty, contains an externally supplied path that should be used as
369 // the target path. 369 // the target path.
370 FilePath forced_file_path_; 370 base::FilePath forced_file_path_;
371 371
372 // Page transition that triggerred the download. 372 // Page transition that triggerred the download.
373 PageTransition transition_type_; 373 PageTransition transition_type_;
374 374
375 // Whether the download was triggered with a user gesture. 375 // Whether the download was triggered with a user gesture.
376 bool has_user_gesture_; 376 bool has_user_gesture_;
377 377
378 // Information from the request. 378 // Information from the request.
379 // Content-disposition field from the header. 379 // Content-disposition field from the header.
380 std::string content_disposition_; 380 std::string content_disposition_;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 const net::BoundNetLog bound_net_log_; 481 const net::BoundNetLog bound_net_log_;
482 482
483 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; 483 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_;
484 484
485 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 485 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
486 }; 486 };
487 487
488 } // namespace content 488 } // namespace content
489 489
490 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 490 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_file_unittest.cc ('k') | content/browser/download/download_item_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698