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"
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(), ' '));
27 History::History(content::BrowserContext
* context
)
28 : browser_context_(context
),
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
);
38 new HistoryData(store_
.get(), kMaxQueryEntries
, kMaxSecondaryQueries
));
39 data_
->AddObserver(this);
43 data_
->RemoveObserver(this);
46 bool History::IsReady() const {
50 void History::AddLaunchEvent(const std::string
& query
,
51 const std::string
& result_id
) {
53 data_
->Add(NormalizeString(query
), result_id
);
56 scoped_ptr
<KnownResults
> History::GetKnownResults(
57 const std::string
& query
) const {
59 return data_
->GetKnownResults(NormalizeString(query
)).Pass();
62 void History::OnHistoryDataLoadedFromStore() {
66 } // namespace app_list