| OLD | NEW |
| 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 #include "chrome/browser/history/in_memory_history_backend.h" | 5 #include "chrome/browser/history/in_memory_history_backend.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/histogram.h" | 8 #include "base/histogram.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | |
| 11 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/history/history_notifications.h" | 11 #include "chrome/browser/history/history_notifications.h" |
| 13 #include "chrome/browser/history/in_memory_database.h" | 12 #include "chrome/browser/history/in_memory_database.h" |
| 14 #include "chrome/browser/history/in_memory_url_index.h" | 13 #include "chrome/browser/history/in_memory_url_index.h" |
| 15 #include "chrome/browser/history/url_database.h" | 14 #include "chrome/browser/history/url_database.h" |
| 16 #include "chrome/browser/pref_service.h" | |
| 17 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
| 18 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
| 20 #include "chrome/common/pref_names.h" | |
| 21 | 18 |
| 22 namespace history { | 19 namespace history { |
| 23 | 20 |
| 24 // If a page becomes starred we use this id in place of the real starred id. | 21 // If a page becomes starred we use this id in place of the real starred id. |
| 25 // See note in OnURLsStarred. | 22 // See note in OnURLsStarred. |
| 26 static const StarID kBogusStarredID = 0x0FFFFFFF; | 23 static const StarID kBogusStarredID = 0x0FFFFFFF; |
| 27 | 24 |
| 28 InMemoryHistoryBackend::InMemoryHistoryBackend() | 25 InMemoryHistoryBackend::InMemoryHistoryBackend() |
| 29 : profile_(NULL) { | 26 : profile_(NULL) { |
| 30 } | 27 } |
| 31 | 28 |
| 32 InMemoryHistoryBackend::~InMemoryHistoryBackend() { | 29 InMemoryHistoryBackend::~InMemoryHistoryBackend() { |
| 33 } | 30 } |
| 34 | 31 |
| 35 bool InMemoryHistoryBackend::Init(const FilePath& history_filename, | 32 bool InMemoryHistoryBackend::Init(const FilePath& history_filename, |
| 36 URLDatabase* db) { | 33 URLDatabase* db) { |
| 37 db_.reset(new InMemoryDatabase); | 34 db_.reset(new InMemoryDatabase); |
| 38 bool success = db_->InitFromDisk(history_filename); | 35 bool success = db_->InitFromDisk(history_filename); |
| 39 | 36 |
| 40 if (CommandLine::ForCurrentProcess()->HasSwitch( | 37 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 41 switches::kEnableInMemoryURLIndex)) { | 38 switches::kEnableInMemoryURLIndex)) { |
| 42 index_.reset(new InMemoryURLIndex()); | 39 index_.reset(new InMemoryURLIndex); |
| 43 base::TimeTicks beginning_time = base::TimeTicks::Now(); | 40 base::TimeTicks beginning_time = base::TimeTicks::Now(); |
| 44 string16 languages = | 41 index_->Init(db); |
| 45 UTF8ToUTF16(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | |
| 46 index_->Init(db, languages); | |
| 47 UMA_HISTOGRAM_TIMES("Autocomplete.HistoryDatabaseIndexingTime", | 42 UMA_HISTOGRAM_TIMES("Autocomplete.HistoryDatabaseIndexingTime", |
| 48 base::TimeTicks::Now() - beginning_time); | 43 base::TimeTicks::Now() - beginning_time); |
| 49 } | 44 } |
| 50 | 45 |
| 51 return success; | 46 return success; |
| 52 } | 47 } |
| 53 | 48 |
| 54 void InMemoryHistoryBackend::AttachToHistoryService(Profile* profile) { | 49 void InMemoryHistoryBackend::AttachToHistoryService(Profile* profile) { |
| 55 if (!db_.get()) { | 50 if (!db_.get()) { |
| 56 NOTREACHED(); | 51 NOTREACHED(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 URLID id = db_->GetRowForURL(*i, NULL); | 133 URLID id = db_->GetRowForURL(*i, NULL); |
| 139 if (id) { | 134 if (id) { |
| 140 // We typically won't have most of them since we only have a subset of | 135 // We typically won't have most of them since we only have a subset of |
| 141 // history, so ignore errors. | 136 // history, so ignore errors. |
| 142 db_->DeleteURLRow(id); | 137 db_->DeleteURLRow(id); |
| 143 } | 138 } |
| 144 } | 139 } |
| 145 } | 140 } |
| 146 | 141 |
| 147 } // namespace history | 142 } // namespace history |
| OLD | NEW |