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

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

Issue 7237034: sql::MetaTable.next_download_id, DownloadManager::GetNextId() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: " Created 9 years, 4 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) 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 // The DownloadManager object manages the process of downloading, including 5 // The DownloadManager object manages the process of downloading, including
6 // updates to the history system and providing the information for displaying 6 // updates to the history system and providing the information for displaying
7 // the downloads view in the Destinations tab. There is one DownloadManager per 7 // the downloads view in the Destinations tab. There is one DownloadManager per
8 // active profile in Chrome. 8 // active profile in Chrome.
9 // 9 //
10 // Download observers: 10 // Download observers:
(...skipping 16 matching lines...) Expand all
27 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ 27 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_
28 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ 28 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_
29 #pragma once 29 #pragma once
30 30
31 #include <map> 31 #include <map>
32 #include <set> 32 #include <set>
33 #include <string> 33 #include <string>
34 #include <vector> 34 #include <vector>
35 35
36 #include "base/basictypes.h" 36 #include "base/basictypes.h"
37 #include "base/callback.h"
37 #include "base/file_path.h" 38 #include "base/file_path.h"
38 #include "base/gtest_prod_util.h" 39 #include "base/gtest_prod_util.h"
39 #include "base/hash_tables.h" 40 #include "base/hash_tables.h"
40 #include "base/memory/ref_counted.h" 41 #include "base/memory/ref_counted.h"
41 #include "base/memory/scoped_ptr.h" 42 #include "base/memory/scoped_ptr.h"
42 #include "base/memory/weak_ptr.h" 43 #include "base/memory/weak_ptr.h"
43 #include "base/observer_list.h" 44 #include "base/observer_list.h"
45 #include "base/synchronization/lock.h"
44 #include "base/time.h" 46 #include "base/time.h"
45 #include "chrome/browser/download/download_item.h" 47 #include "chrome/browser/download/download_item.h"
46 #include "chrome/browser/download/download_request_handle.h" 48 #include "chrome/browser/download/download_request_handle.h"
49 #include "chrome/browser/download/download_state_info.h"
47 #include "chrome/browser/download/download_status_updater_delegate.h" 50 #include "chrome/browser/download/download_status_updater_delegate.h"
48 #include "content/browser/browser_thread.h" 51 #include "content/browser/browser_thread.h"
49 52
50 class DownloadFileManager; 53 class DownloadFileManager;
51 class DownloadHistory; 54 class DownloadHistory;
52 class DownloadManagerDelegate; 55 class DownloadManagerDelegate;
53 class DownloadPrefs; 56 class DownloadPrefs;
54 class DownloadStatusUpdater; 57 class DownloadStatusUpdater;
55 class GURL; 58 class GURL;
56 class Profile; 59 class Profile;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // Return all non-temporary downloads in the specified directory that are 108 // Return all non-temporary downloads in the specified directory that are
106 // in-progress (including dangerous downloads waiting for user confirmation). 109 // in-progress (including dangerous downloads waiting for user confirmation).
107 void GetCurrentDownloads(const FilePath& dir_path, 110 void GetCurrentDownloads(const FilePath& dir_path,
108 std::vector<DownloadItem*>* result); 111 std::vector<DownloadItem*>* result);
109 112
110 // Returns all non-temporary downloads matching |query|. Empty query matches 113 // Returns all non-temporary downloads matching |query|. Empty query matches
111 // everything. 114 // everything.
112 void SearchDownloads(const string16& query, 115 void SearchDownloads(const string16& query,
113 std::vector<DownloadItem*>* result); 116 std::vector<DownloadItem*>* result);
114 117
118 // Returns the next download id in a DownloadId and increments the counter.
119 // May be called on any thread. The incremented counter is not persisted, but
120 // the base counter for this accessor is initialized from the largest id
121 // actually saved to the download history database.
122 DownloadId GetNextId();
123
124 // Instead of passing a DownloadManager* between threads and hoping users only
125 // call GetNextId(), you can pass this thunk around instead. Pass the thunk
126 // around by const ref and store it by copy per the base::Callback interface.
127 // The thunk may be copied, including between threads. If you change
128 // GetNextIdThunkType from base::Callback, then you should think about how
129 // you're changing the ref-count of DownloadManager. Use it like:
130 // const DownloadManager::GetNextIdThunkType& next_id_thunk =
131 // download_manager->GetNextIdThunk();
132 // id = next_id_thunk.Run();
133 typedef base::Callback<DownloadId(void)> GetNextIdThunkType;
134 GetNextIdThunkType GetNextIdThunk();
135
115 // Returns true if initialized properly. 136 // Returns true if initialized properly.
116 bool Init(Profile* profile); 137 bool Init(Profile* profile);
117 138
118 // Notifications sent from the download thread to the UI thread 139 // Notifications sent from the download thread to the UI thread
119 void StartDownload(int32 id); 140 void StartDownload(int32 id);
120 void UpdateDownload(int32 download_id, int64 size); 141 void UpdateDownload(int32 download_id, int64 size);
121 // |hash| is sha256 hash for the downloaded file. It is empty when the hash 142 // |hash| is sha256 hash for the downloaded file. It is empty when the hash
122 // is not available. 143 // is not available.
123 void OnResponseCompleted(int32 download_id, int64 size, int os_error, 144 void OnResponseCompleted(int32 download_id, int64 size, int os_error,
124 const std::string& hash); 145 const std::string& hash);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // yet in the history map. 366 // yet in the history map.
346 DownloadItem* GetActiveDownloadItem(int id); 367 DownloadItem* GetActiveDownloadItem(int id);
347 368
348 // Debugging routine to confirm relationship between below 369 // Debugging routine to confirm relationship between below
349 // containers; no-op if NDEBUG. 370 // containers; no-op if NDEBUG.
350 void AssertContainersConsistent() const; 371 void AssertContainersConsistent() const;
351 372
352 // Add a DownloadItem to history_downloads_. 373 // Add a DownloadItem to history_downloads_.
353 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); 374 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle);
354 375
376 // The DownloadHistory grabbed the next_id counter from the sql MetaTable.
377 void OnHistoryGetNextId(int next_id);
378
355 // |downloads_| is the owning set for all downloads known to the 379 // |downloads_| is the owning set for all downloads known to the
356 // DownloadManager. This includes downloads started by the user in 380 // DownloadManager. This includes downloads started by the user in
357 // this session, downloads initialized from the history system, and 381 // this session, downloads initialized from the history system, and
358 // "save page as" downloads. All other DownloadItem containers in 382 // "save page as" downloads. All other DownloadItem containers in
359 // the DownloadManager are maps; they do not own the DownloadItems. 383 // the DownloadManager are maps; they do not own the DownloadItems.
360 // Note that this is the only place (with any functional implications; 384 // Note that this is the only place (with any functional implications;
361 // see save_page_as_downloads_ below) that "save page as" downloads are 385 // see save_page_as_downloads_ below) that "save page as" downloads are
362 // kept, as the DownloadManager's only job is to hold onto those 386 // kept, as the DownloadManager's only job is to hold onto those
363 // until destruction. 387 // until destruction.
364 // 388 //
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 #if !defined(NDEBUG) 422 #if !defined(NDEBUG)
399 DownloadSet save_page_as_downloads_; 423 DownloadSet save_page_as_downloads_;
400 #endif 424 #endif
401 425
402 // True if the download manager has been initialized and requires a shutdown. 426 // True if the download manager has been initialized and requires a shutdown.
403 bool shutdown_needed_; 427 bool shutdown_needed_;
404 428
405 // Observers that want to be notified of changes to the set of downloads. 429 // Observers that want to be notified of changes to the set of downloads.
406 ObserverList<Observer> observers_; 430 ObserverList<Observer> observers_;
407 431
432 base::Lock next_id_lock_;
433 int next_id_;
434
408 // The current active profile. 435 // The current active profile.
409 Profile* profile_; 436 Profile* profile_;
410 437
411 scoped_ptr<DownloadHistory> download_history_; 438 scoped_ptr<DownloadHistory> download_history_;
412 439
413 scoped_ptr<DownloadPrefs> download_prefs_; 440 scoped_ptr<DownloadPrefs> download_prefs_;
414 441
415 // Non-owning pointer for handling file writing on the download_thread_. 442 // Non-owning pointer for handling file writing on the download_thread_.
416 DownloadFileManager* file_manager_; 443 DownloadFileManager* file_manager_;
417 444
418 // Non-owning pointer for updating the download status. 445 // Non-owning pointer for updating the download status.
419 base::WeakPtr<DownloadStatusUpdater> status_updater_; 446 base::WeakPtr<DownloadStatusUpdater> status_updater_;
420 447
421 // The user's last choice for download directory. This is only used when the 448 // The user's last choice for download directory. This is only used when the
422 // user wants us to prompt for a save location for each download. 449 // user wants us to prompt for a save location for each download.
423 FilePath last_download_path_; 450 FilePath last_download_path_;
424 451
425 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; 452 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_;
426 453
427 // Allows an embedder to control behavior. Guaranteed to outlive this object. 454 // Allows an embedder to control behavior. Guaranteed to outlive this object.
428 DownloadManagerDelegate* delegate_; 455 DownloadManagerDelegate* delegate_;
429 456
430 DISALLOW_COPY_AND_ASSIGN(DownloadManager); 457 DISALLOW_COPY_AND_ASSIGN(DownloadManager);
431 }; 458 };
432 459
433 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ 460 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698