Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / app_list / search / history.cc
blob534fda7249fe2108442c23af1efeb2449f63f11a
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/app_list/search/history.h"
7 #include "base/files/file_path.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/app_list/search/history_data.h"
11 #include "chrome/browser/ui/app_list/search/history_data_store.h"
12 #include "chrome/browser/ui/app_list/search/tokenized_string.h"
13 #include "content/public/browser/browser_context.h"
15 namespace app_list {
17 namespace {
19 // Normalize the given string by joining all its tokens with a space.
20 std::string NormalizeString(const std::string& utf8) {
21 TokenizedString tokenized(base::UTF8ToUTF16(utf8));
22 return base::UTF16ToUTF8(JoinString(tokenized.tokens(), ' '));
25 } // namespace
27 History::History(content::BrowserContext* context)
28 : browser_context_(context),
29 data_loaded_(false) {
30 const char kStoreDataFileName[] = "App Launcher Search";
31 const size_t kMaxQueryEntries = 1000;
32 const size_t kMaxSecondaryQueries = 5;
34 const base::FilePath data_file =
35 browser_context_->GetPath().AppendASCII(kStoreDataFileName);
36 store_ = new HistoryDataStore(data_file);
37 data_.reset(
38 new HistoryData(store_.get(), kMaxQueryEntries, kMaxSecondaryQueries));
39 data_->AddObserver(this);
42 History::~History() {
43 data_->RemoveObserver(this);
46 bool History::IsReady() const {
47 return data_loaded_;
50 void History::AddLaunchEvent(const std::string& query,
51 const std::string& result_id) {
52 DCHECK(IsReady());
53 data_->Add(NormalizeString(query), result_id);
56 scoped_ptr<KnownResults> History::GetKnownResults(
57 const std::string& query) const {
58 DCHECK(IsReady());
59 return data_->GetKnownResults(NormalizeString(query)).Pass();
62 void History::OnHistoryDataLoadedFromStore() {
63 data_loaded_ = true;
66 } // namespace app_list