diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-02 20:09:16 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-02 20:09:16 +0000 |
commit | aa9d4a9eab291ef35d6aed3fb390e0c7a76c8cc1 (patch) | |
tree | 94f7eb2d1e1277ab0a52fb9594b86c652af12acd /chrome/browser | |
parent | 83421477bc9698c3f0c9de41764eb85dfc162ba7 (diff) | |
download | chromium_src-aa9d4a9eab291ef35d6aed3fb390e0c7a76c8cc1.zip chromium_src-aa9d4a9eab291ef35d6aed3fb390e0c7a76c8cc1.tar.gz chromium_src-aa9d4a9eab291ef35d6aed3fb390e0c7a76c8cc1.tar.bz2 |
Adds the --enable-in-memory-url-index switch to gate creation and use of the InMemoryURLIndex.
BUG=19736
TEST=No change in behavior when flag is not used. Should not crash when flag is used.
Review URL: http://codereview.chromium.org/2861041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51555 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/autocomplete/history_url_provider.cc | 46 | ||||
-rw-r--r-- | chrome/browser/history/in_memory_history_backend.cc | 15 | ||||
-rw-r--r-- | chrome/browser/history/in_memory_history_backend.h | 11 |
3 files changed, 50 insertions, 22 deletions
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc index f1bd7f9..c3cc345 100644 --- a/chrome/browser/autocomplete/history_url_provider.cc +++ b/chrome/browser/autocomplete/history_url_provider.cc @@ -7,6 +7,7 @@ #include <algorithm> #include "base/basictypes.h" +#include "base/command_line.h" #include "base/histogram.h" #include "base/message_loop.h" #include "base/string_util.h" @@ -17,6 +18,7 @@ #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/common/sqlite_utils.h" #include "chrome/common/url_constants.h" @@ -149,25 +151,31 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, typedef std::vector<history::URLRow> URLRowVector; URLRowVector url_matches; HistoryMatches history_matches; - for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end(); - ++i) { - if (params->cancel) - return; // Canceled in the middle of a query, give up. - // We only need kMaxMatches results in the end, but before we get there we - // need to promote lower-quality matches that are prefixes of - // higher-quality matches, and remove lower-quality redirects. So we ask - // for more results than we need, of every prefix type, in hopes this will - // give us far more than enough to work with. CullRedirects() will then - // reduce the list to the best kMaxMatches results. - db->AutocompleteForPrefix(WideToUTF16(i->prefix + params->input.text()), - kMaxMatches * 2, &url_matches); - for (URLRowVector::const_iterator j(url_matches.begin()); - j != url_matches.end(); ++j) { - const Prefix* best_prefix = BestPrefix(j->url(), std::wstring()); - DCHECK(best_prefix != NULL); - history_matches.push_back(HistoryMatch(*j, i->prefix.length(), - !i->num_components, - i->num_components >= best_prefix->num_components)); + + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableInMemoryURLIndex)) { + // TODO(rohitrao): Fetch results from the index. + } else { + for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end(); + ++i) { + if (params->cancel) + return; // Canceled in the middle of a query, give up. + // We only need kMaxMatches results in the end, but before we get there we + // need to promote lower-quality matches that are prefixes of + // higher-quality matches, and remove lower-quality redirects. So we ask + // for more results than we need, of every prefix type, in hopes this will + // give us far more than enough to work with. CullRedirects() will then + // reduce the list to the best kMaxMatches results. + db->AutocompleteForPrefix(WideToUTF16(i->prefix + params->input.text()), + kMaxMatches * 2, &url_matches); + for (URLRowVector::const_iterator j(url_matches.begin()); + j != url_matches.end(); ++j) { + const Prefix* best_prefix = BestPrefix(j->url(), std::wstring()); + DCHECK(best_prefix != NULL); + history_matches.push_back(HistoryMatch(*j, i->prefix.length(), + !i->num_components, + i->num_components >= best_prefix->num_components)); + } } } diff --git a/chrome/browser/history/in_memory_history_backend.cc b/chrome/browser/history/in_memory_history_backend.cc index d40c581..9f3e7be 100644 --- a/chrome/browser/history/in_memory_history_backend.cc +++ b/chrome/browser/history/in_memory_history_backend.cc @@ -1,13 +1,16 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/history/in_memory_history_backend.h" +#include "base/command_line.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/history/history_notifications.h" #include "chrome/browser/history/in_memory_database.h" +#include "chrome/browser/history/in_memory_url_index.h" #include "chrome/browser/profile.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" namespace history { @@ -25,7 +28,15 @@ InMemoryHistoryBackend::~InMemoryHistoryBackend() { bool InMemoryHistoryBackend::Init(const FilePath& history_filename) { db_.reset(new InMemoryDatabase); - return db_->InitFromDisk(history_filename); + bool success = db_->InitFromDisk(history_filename); + + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableInMemoryURLIndex)) { + index_.reset(new InMemoryURLIndex); + // TODO(rohitrao): Load index. + } + + return success; } void InMemoryHistoryBackend::AttachToHistoryService(Profile* profile) { diff --git a/chrome/browser/history/in_memory_history_backend.h b/chrome/browser/history/in_memory_history_backend.h index 18184bf..30026b5 100644 --- a/chrome/browser/history/in_memory_history_backend.h +++ b/chrome/browser/history/in_memory_history_backend.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -27,6 +27,7 @@ class Profile; namespace history { class InMemoryDatabase; +class InMemoryURLIndex; struct URLsDeletedDetails; struct URLsModifiedDetails; @@ -50,6 +51,12 @@ class InMemoryHistoryBackend : public NotificationObserver { return db_.get(); } + // Returns the in memory index owned by this backend. This index is only + // loaded when the --enable-in-memory-url-index flag is used. + InMemoryURLIndex* index() const { + return index_.get(); + } + // Notification callback. virtual void Observe(NotificationType type, const NotificationSource& source, @@ -68,6 +75,8 @@ class InMemoryHistoryBackend : public NotificationObserver { scoped_ptr<InMemoryDatabase> db_; + scoped_ptr<InMemoryURLIndex> index_; + // The profile that this object is attached. May be NULL before // initialization. Profile* profile_; |