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

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

Issue 8571023: Implemented ExternalData interface on DownloadItem and used it for SafeBrowsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up a bit. Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Each download is represented by a DownloadItem, and all DownloadItems 5 // Each download is represented by a DownloadItem, and all DownloadItems
6 // are owned by the DownloadManager which maintains a global list of all 6 // are owned by the DownloadManager which maintains a global list of all
7 // downloads. DownloadItems are created when a user initiates a download, 7 // downloads. DownloadItems are created when a user initiates a download,
8 // and exist for the duration of the browser life time. 8 // and exist for the duration of the browser life time.
9 // 9 //
10 // Download observers: 10 // Download observers:
11 // DownloadItem::Observer: 11 // DownloadItem::Observer:
12 // - allows observers to receive notifications about one download from start 12 // - allows observers to receive notifications about one download from start
13 // to completion 13 // to completion
14 // Use AddObserver() / RemoveObserver() on the appropriate download object to 14 // Use AddObserver() / RemoveObserver() on the appropriate download object to
15 // receive state updates. 15 // receive state updates.
16 16
17 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ 17 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_
18 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ 18 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_
19 #pragma once 19 #pragma once
20 20
21 #include <map>
21 #include <string> 22 #include <string>
22 23
23 #include "base/basictypes.h" 24 #include "base/basictypes.h"
24 #include "base/file_path.h" 25 #include "base/file_path.h"
25 #include "base/memory/scoped_ptr.h" 26 #include "base/memory/scoped_ptr.h"
26 #include "base/observer_list.h" 27 #include "base/observer_list.h"
27 #include "base/time.h" 28 #include "base/time.h"
28 #include "content/browser/download/download_id.h" 29 #include "content/browser/download/download_id.h"
29 #include "content/browser/download/download_request_handle.h" 30 #include "content/browser/download/download_request_handle.h"
30 #include "content/browser/download/download_state_info.h" 31 #include "content/browser/download/download_state_info.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 public: 111 public:
111 virtual void OnDownloadUpdated(DownloadItem* download) = 0; 112 virtual void OnDownloadUpdated(DownloadItem* download) = 0;
112 113
113 // Called when a downloaded file has been opened. 114 // Called when a downloaded file has been opened.
114 virtual void OnDownloadOpened(DownloadItem* download) = 0; 115 virtual void OnDownloadOpened(DownloadItem* download) = 0;
115 116
116 protected: 117 protected:
117 virtual ~Observer() {} 118 virtual ~Observer() {}
118 }; 119 };
119 120
121 // Interface for data that can be stored associated with (and owned
122 // by) an object of this class via GetExternalData/SetExternalData.
123 class ExternalData {
124 public:
125 virtual ~ExternalData() {};
126 };
127
120 // Constructing from persistent store: 128 // Constructing from persistent store:
121 DownloadItem(DownloadManager* download_manager, 129 DownloadItem(DownloadManager* download_manager,
122 const DownloadPersistentStoreInfo& info); 130 const DownloadPersistentStoreInfo& info);
123 131
124 // Constructing for a regular download. 132 // Constructing for a regular download.
125 // Takes ownership of the object pointed to by |request_handle|. 133 // Takes ownership of the object pointed to by |request_handle|.
126 DownloadItem(DownloadManager* download_manager, 134 DownloadItem(DownloadManager* download_manager,
127 const DownloadCreateInfo& info, 135 const DownloadCreateInfo& info,
128 DownloadRequestHandleInterface* request_handle, 136 DownloadRequestHandleInterface* request_handle,
129 bool is_otr); 137 bool is_otr);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // DownloadItem::Cancel/Interrupt; it isn't now because we can't 350 // DownloadItem::Cancel/Interrupt; it isn't now because we can't
343 // call those functions from 351 // call those functions from
344 // DownloadManager::FileSelectionCancelled() without doing some 352 // DownloadManager::FileSelectionCancelled() without doing some
345 // rewrites of the DownloadManager queues. 353 // rewrites of the DownloadManager queues.
346 void OffThreadCancel(DownloadFileManager* file_manager); 354 void OffThreadCancel(DownloadFileManager* file_manager);
347 355
348 std::string DebugString(bool verbose) const; 356 std::string DebugString(bool verbose) const;
349 357
350 void MockDownloadOpenForTesting() { open_enabled_ = false; } 358 void MockDownloadOpenForTesting() { open_enabled_ = false; }
351 359
360 // Manage data owned by other subsystems associated with the
361 // DownloadItem. By custom, key is the address of a
362 // static char subsystem_specific_string[] = ".."; defined
363 // in the subsystem, but the only requirement of this interface
364 // is that the key be unique over all data stored with this
365 // DownloadItem.
366 //
367 // Note that SetExternalData takes ownership of the
368 // passed object; it will be destroyed when the DownloadItem is.
369 // If an object is already held by the DownloadItem associated with
370 // the passed key, it will be destroyed on overwrite.
371 ExternalData* GetExternalData(void* key);
372 void SetExternalData(void* key, ExternalData* data);
373
352 private: 374 private:
353 // Construction common to all constructors. |active| should be true for new 375 // Construction common to all constructors. |active| should be true for new
354 // downloads and false for downloads from the history. 376 // downloads and false for downloads from the history.
355 void Init(bool active); 377 void Init(bool active);
356 378
357 // Internal helper for maintaining consistent received and total sizes. 379 // Internal helper for maintaining consistent received and total sizes.
358 void UpdateSize(int64 size); 380 void UpdateSize(int64 size);
359 381
360 // Called when the entire download operation (including renaming etc) 382 // Called when the entire download operation (including renaming etc)
361 // is completed. 383 // is completed.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // be treated as though the user opened it. 507 // be treated as though the user opened it.
486 bool opened_; 508 bool opened_;
487 509
488 // Do we actual open downloads when requested? For testing purposes 510 // Do we actual open downloads when requested? For testing purposes
489 // only. 511 // only.
490 bool open_enabled_; 512 bool open_enabled_;
491 513
492 // Did the delegate delay calling Complete on this download? 514 // Did the delegate delay calling Complete on this download?
493 bool delegate_delayed_complete_; 515 bool delegate_delayed_complete_;
494 516
517 // External Data storage. All objects in the store
518 // are owned by the DownloadItem.
519 std::map<void*, ExternalData*> external_data_map_;
asanka 2011/11/16 03:52:19 Would a std::map<const void*, ExternalData*> be be
Randy Smith (Not in Mondays) 2011/11/18 02:02:57 Done.
520
495 DISALLOW_COPY_AND_ASSIGN(DownloadItem); 521 DISALLOW_COPY_AND_ASSIGN(DownloadItem);
496 }; 522 };
497 523
498 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ 524 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698