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

Side by Side Diff: chrome/browser/history/text_database.cc

Issue 4247: Port some things in browser/{download,history}, minor things in common.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 2 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/history/snippet.h ('k') | chrome/browser/history/text_database_manager.cc » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <limits> 5 #include <limits>
6 #include <set> 6 #include <set>
7 7
8 #include "chrome/browser/history/text_database.h" 8 #include "chrome/browser/history/text_database.h"
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 return StringPrintf(L"%ls%d-%02d", file_base(), id / 100, id % 100); 108 return StringPrintf(L"%ls%d-%02d", file_base(), id / 100, id % 100);
109 } 109 }
110 110
111 // static 111 // static
112 TextDatabase::DBIdent TextDatabase::FileNameToID(const std::wstring& file_path){ 112 TextDatabase::DBIdent TextDatabase::FileNameToID(const std::wstring& file_path){
113 std::wstring file_name = file_util::GetFilenameFromPath(file_path); 113 std::wstring file_name = file_util::GetFilenameFromPath(file_path);
114 114
115 // We don't actually check the prefix here. Since the file system could 115 // We don't actually check the prefix here. Since the file system could
116 // be case insensitive in ways we can't predict (NTFS), checking could 116 // be case insensitive in ways we can't predict (NTFS), checking could
117 // potentially be the wrong thing to do. Instead, we just look for a suffix. 117 // potentially be the wrong thing to do. Instead, we just look for a suffix.
118 static const int kIDStringLength = 7; // Room for "xxxx-xx". 118 static const size_t kIDStringLength = 7; // Room for "xxxx-xx".
119 if (file_name.length() < kIDStringLength) 119 if (file_name.length() < kIDStringLength)
120 return 0; 120 return 0;
121 const wchar_t* number_begin = 121 const std::wstring suffix(&file_name[file_name.length() - kIDStringLength]);
122 &file_name[file_name.length() - kIDStringLength];
123 122
124 int year, month; 123 if (suffix.length() != kIDStringLength || suffix[4] != L'-') {
125 if (swscanf_s(number_begin, L"%d-%d", &year, &month) != 2) 124 return 0;
126 return 0; // Unable to get both numbers. 125 }
126
127 int year = StringToInt(suffix.substr(0, 4));
128 int month = StringToInt(suffix.substr(5, 2));
127 129
128 return year * 100 + month; 130 return year * 100 + month;
129 } 131 }
130 132
131 bool TextDatabase::Init() { 133 bool TextDatabase::Init() {
132 // Make sure, if we're not allowed to create the file, that it exists. 134 // Make sure, if we're not allowed to create the file, that it exists.
133 if (!allow_create_) { 135 if (!allow_create_) {
134 if (!file_util::PathExists(file_name_)) 136 if (!file_util::PathExists(file_name_))
135 return false; 137 return false;
136 } 138 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 URLSet::const_iterator found_url = found_urls->find(url); 343 URLSet::const_iterator found_url = found_urls->find(url);
342 if (found_url != found_urls->end()) 344 if (found_url != found_urls->end())
343 continue; // Don't add this duplicate when unique URLs are requested. 345 continue; // Don't add this duplicate when unique URLs are requested.
344 } 346 }
345 347
346 // Fill the results into the vector (avoid copying the URL with Swap()). 348 // Fill the results into the vector (avoid copying the URL with Swap()).
347 results->resize(results->size() + 1); 349 results->resize(results->size() + 1);
348 Match& match = results->at(results->size() - 1); 350 Match& match = results->at(results->size() - 1);
349 match.url.Swap(&url); 351 match.url.Swap(&url);
350 352
351 match.title = statement->column_string16(1); 353 match.title = UTF8ToWide(statement->column_string(1));
352 match.time = Time::FromInternalValue(statement->column_int64(2)); 354 match.time = Time::FromInternalValue(statement->column_int64(2));
353 355
354 // Extract any matches in the title. 356 // Extract any matches in the title.
355 std::string offsets_str = statement->column_string(3); 357 std::string offsets_str = statement->column_string(3);
356 Snippet::ExtractMatchPositions(offsets_str, kTitleColumnIndex, 358 Snippet::ExtractMatchPositions(offsets_str, kTitleColumnIndex,
357 &match.title_match_positions); 359 &match.title_match_positions);
358 Snippet::ConvertMatchPositionsToWide(statement->column_string(1), 360 Snippet::ConvertMatchPositionsToWide(statement->column_string(1),
359 &match.title_match_positions); 361 &match.title_match_positions);
360 362
361 // Extract the matches in the body. 363 // Extract the matches in the body.
(...skipping 17 matching lines...) Expand all
379 // Since we got the results in order, we know the last item is the last 381 // Since we got the results in order, we know the last item is the last
380 // time we considered. 382 // time we considered.
381 *first_time_searched = results->back().time; 383 *first_time_searched = results->back().time;
382 } 384 }
383 385
384 statement->reset(); 386 statement->reset();
385 } 387 }
386 388
387 } // namespace history 389 } // namespace history
388 390
OLDNEW
« no previous file with comments | « chrome/browser/history/snippet.h ('k') | chrome/browser/history/text_database_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698