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

Side by Side Diff: chrome/browser/download/download_history.cc

Issue 6969009: Reduced the lifetime of DownloadCreateInfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Stupid clang! Created 9 years, 7 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 | « chrome/browser/download/download_history.h ('k') | chrome/browser/download/download_item.h » ('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) 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 #include "chrome/browser/download/download_history.h" 5 #include "chrome/browser/download/download_history.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/history/download_create_info.h" 8 #include "chrome/browser/history/download_history_info.h"
9 #include "chrome/browser/history/history_marshaling.h" 9 #include "chrome/browser/history/history_marshaling.h"
10 #include "chrome/browser/download/download_item.h" 10 #include "chrome/browser/download/download_item.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 12
13 // Our download table ID starts at 1, so we use 0 to represent a download that 13 // Our download table ID starts at 1, so we use 0 to represent a download that
14 // has started, but has not yet had its data persisted in the table. We use fake 14 // has started, but has not yet had its data persisted in the table. We use fake
15 // database handles in incognito mode starting at -1 and progressively getting 15 // database handles in incognito mode starting at -1 and progressively getting
16 // more negative. 16 // more negative.
17 // static 17 // static
18 const int DownloadHistory::kUninitializedHandle = 0; 18 const int DownloadHistory::kUninitializedHandle = 0;
(...skipping 14 matching lines...) Expand all
33 delete callback; 33 delete callback;
34 return; 34 return;
35 } 35 }
36 hs->QueryDownloads(&history_consumer_, callback); 36 hs->QueryDownloads(&history_consumer_, callback);
37 37
38 // This is the initial load, so do a cleanup of corrupt in-progress entries. 38 // This is the initial load, so do a cleanup of corrupt in-progress entries.
39 hs->CleanUpInProgressEntries(); 39 hs->CleanUpInProgressEntries();
40 } 40 }
41 41
42 void DownloadHistory::AddEntry( 42 void DownloadHistory::AddEntry(
43 const DownloadCreateInfo& info,
44 DownloadItem* download_item, 43 DownloadItem* download_item,
45 HistoryService::DownloadCreateCallback* callback) { 44 HistoryService::DownloadCreateCallback* callback) {
45 DCHECK(download_item);
46 // Do not store the download in the history database for a few special cases: 46 // Do not store the download in the history database for a few special cases:
47 // - incognito mode (that is the point of this mode) 47 // - incognito mode (that is the point of this mode)
48 // - extensions (users don't think of extension installation as 'downloading') 48 // - extensions (users don't think of extension installation as 'downloading')
49 // - temporary download, like in drag-and-drop 49 // - temporary download, like in drag-and-drop
50 // - history service is not available (e.g. in tests) 50 // - history service is not available (e.g. in tests)
51 // We have to make sure that these handles don't collide with normal db 51 // We have to make sure that these handles don't collide with normal db
52 // handles, so we use a negative value. Eventually, they could overlap, but 52 // handles, so we use a negative value. Eventually, they could overlap, but
53 // you'd have to do enough downloading that your ISP would likely stab you in 53 // you'd have to do enough downloading that your ISP would likely stab you in
54 // the neck first. YMMV. 54 // the neck first. YMMV.
55 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. 55 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong.
56 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 56 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
57 if (download_item->is_otr() || download_item->is_extension_install() || 57 if (download_item->is_otr() || download_item->is_extension_install() ||
58 download_item->is_temporary() || !hs) { 58 download_item->is_temporary() || !hs) {
59 callback->RunWithParams( 59 callback->RunWithParams(
60 history::DownloadCreateRequest::TupleType(info, GetNextFakeDbHandle())); 60 history::DownloadCreateRequest::TupleType(download_item->id(),
61 GetNextFakeDbHandle()));
61 delete callback; 62 delete callback;
62 return; 63 return;
63 } 64 }
64 65
65 hs->CreateDownload(info, &history_consumer_, callback); 66 int32 id = download_item->id();
67 DownloadHistoryInfo history_info = download_item->GetHistoryInfo();
68 hs->CreateDownload(id, history_info, &history_consumer_, callback);
66 } 69 }
67 70
68 void DownloadHistory::UpdateEntry(DownloadItem* download_item) { 71 void DownloadHistory::UpdateEntry(DownloadItem* download_item) {
69 // Don't store info in the database if the download was initiated while in 72 // Don't store info in the database if the download was initiated while in
70 // incognito mode or if it hasn't been initialized in our database table. 73 // incognito mode or if it hasn't been initialized in our database table.
71 if (download_item->db_handle() <= kUninitializedHandle) 74 if (download_item->db_handle() <= kUninitializedHandle)
72 return; 75 return;
73 76
74 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. 77 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong.
75 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 78 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 const base::Time remove_end) { 111 const base::Time remove_end) {
109 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. 112 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong.
110 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 113 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
111 if (hs) 114 if (hs)
112 hs->RemoveDownloadsBetween(remove_begin, remove_end); 115 hs->RemoveDownloadsBetween(remove_begin, remove_end);
113 } 116 }
114 117
115 int64 DownloadHistory::GetNextFakeDbHandle() { 118 int64 DownloadHistory::GetNextFakeDbHandle() {
116 return next_fake_db_handle_--; 119 return next_fake_db_handle_--;
117 } 120 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_history.h ('k') | chrome/browser/download/download_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698