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

Side by Side Diff: chrome/browser/profile_resetter/automatic_profile_resetter_mementos.cc

Issue 27030002: Added collecting of data to be fed to the JTL interpreter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments from vasilii@. Created 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/profile_resetter/automatic_profile_resetter_mementos.h" 5 #include "chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/prefs/scoped_user_pref_update.h" 14 #include "chrome/browser/prefs/scoped_user_pref_update.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 19
20 using base::DictionaryValue; 20 using base::DictionaryValue;
21 21
22 // AutomaticProfileResetter::PreferenceHostedPromptMemento ------------------- 22 // AutomaticProfileResetter::PreferenceHostedPromptMemento -------------------
23 23
24 PreferenceHostedPromptMemento::PreferenceHostedPromptMemento(Profile* profile) 24 PreferenceHostedPromptMemento::PreferenceHostedPromptMemento(Profile* profile)
25 : profile_(profile) {} 25 : profile_(profile) {}
26 PreferenceHostedPromptMemento::~PreferenceHostedPromptMemento() {} 26 PreferenceHostedPromptMemento::~PreferenceHostedPromptMemento() {}
vasilii 2013/10/17 10:57:57 Blank line above.
engedy 2013/10/17 15:13:47 Done.
27 27
28 std::string PreferenceHostedPromptMemento::ReadValue() const { 28 std::string PreferenceHostedPromptMemento::ReadValue() const {
29 PrefService* prefs = profile_->GetPrefs(); 29 PrefService* prefs = profile_->GetPrefs();
30 DCHECK(prefs); 30 DCHECK(prefs);
31 return prefs->GetString(prefs::kProfileResetPromptMemento); 31 return prefs->GetString(prefs::kProfileResetPromptMemento);
32 } 32 }
33 33
34 void PreferenceHostedPromptMemento::StoreValue(const std::string& value) { 34 void PreferenceHostedPromptMemento::StoreValue(const std::string& value) {
35 PrefService* prefs = profile_->GetPrefs(); 35 PrefService* prefs = profile_->GetPrefs();
36 DCHECK(prefs); 36 DCHECK(prefs);
37 prefs->SetString(prefs::kProfileResetPromptMemento, value); 37 prefs->SetString(prefs::kProfileResetPromptMemento, value);
38 } 38 }
39 39
40 // AutomaticProfileResetter::LocalStateHostedPromptMemento ------------------- 40 // AutomaticProfileResetter::LocalStateHostedPromptMemento -------------------
41 41
42 LocalStateHostedPromptMemento::LocalStateHostedPromptMemento(Profile* profile) 42 LocalStateHostedPromptMemento::LocalStateHostedPromptMemento(Profile* profile)
43 : profile_(profile) {} 43 : profile_(profile) {}
44 LocalStateHostedPromptMemento::~LocalStateHostedPromptMemento() {} 44 LocalStateHostedPromptMemento::~LocalStateHostedPromptMemento() {}
vasilii 2013/10/17 10:57:57 Blank line above.
engedy 2013/10/17 15:13:47 Done.
45 45
46 std::string LocalStateHostedPromptMemento::ReadValue() const { 46 std::string LocalStateHostedPromptMemento::ReadValue() const {
47 PrefService* local_state = g_browser_process->local_state(); 47 PrefService* local_state = g_browser_process->local_state();
48 DCHECK(local_state); 48 DCHECK(local_state);
49 49
50 const DictionaryValue* prompt_shown_dict = 50 const DictionaryValue* prompt_shown_dict =
51 local_state->GetDictionary(prefs::kProfileResetPromptMemento); 51 local_state->GetDictionary(prefs::kProfileResetPromptMemento);
52 std::string profile_key = GetProfileKey(); 52 std::string profile_key = GetProfileKey();
53 if (!prompt_shown_dict || profile_key.empty()) { 53 if (!prompt_shown_dict || profile_key.empty()) {
54 NOTREACHED(); 54 NOTREACHED();
55 return ""; 55 return "";
vasilii 2013/10/17 10:57:57 return std::string();
engedy 2013/10/17 15:13:47 Done.
56 } 56 }
57 std::string value; 57 std::string value;
58 return prompt_shown_dict->GetStringWithoutPathExpansion(profile_key, &value) 58 return prompt_shown_dict->GetStringWithoutPathExpansion(profile_key, &value) ?
59 ? value 59 value : "";
Peter Kasting 2013/10/16 22:36:51 Nit: "" -> std::string()
engedy 2013/10/17 15:13:47 Done.
60 : "";
61 } 60 }
62 61
63 void LocalStateHostedPromptMemento::StoreValue(const std::string& value) { 62 void LocalStateHostedPromptMemento::StoreValue(const std::string& value) {
64 PrefService* local_state = g_browser_process->local_state(); 63 PrefService* local_state = g_browser_process->local_state();
65 DCHECK(local_state); 64 DCHECK(local_state);
66 65
67 DictionaryPrefUpdate prompt_shown_dict_update( 66 DictionaryPrefUpdate prompt_shown_dict_update(
68 local_state, prefs::kProfileResetPromptMemento); 67 local_state, prefs::kProfileResetPromptMemento);
69 std::string profile_key = GetProfileKey(); 68 std::string profile_key = GetProfileKey();
70 if (profile_key.empty()) { 69 if (profile_key.empty()) {
71 NOTREACHED(); 70 NOTREACHED();
72 return; 71 return;
73 } 72 }
74 prompt_shown_dict_update.Get()->SetStringWithoutPathExpansion(profile_key, 73 prompt_shown_dict_update.Get()->SetStringWithoutPathExpansion(profile_key,
75 value); 74 value);
76 } 75 }
77 76
78 std::string LocalStateHostedPromptMemento::GetProfileKey() const { 77 std::string LocalStateHostedPromptMemento::GetProfileKey() const {
79 return profile_->GetPath().BaseName().MaybeAsASCII(); 78 return profile_->GetPath().BaseName().MaybeAsASCII();
80 } 79 }
81 80
82 // AutomaticProfileResetter::FileHostedPromptMemento ------------------------- 81 // AutomaticProfileResetter::FileHostedPromptMemento -------------------------
83 82
84 FileHostedPromptMemento::FileHostedPromptMemento(Profile* profile) 83 FileHostedPromptMemento::FileHostedPromptMemento(Profile* profile)
85 : profile_(profile) {} 84 : profile_(profile) {}
86 FileHostedPromptMemento::~FileHostedPromptMemento() {} 85 FileHostedPromptMemento::~FileHostedPromptMemento() {}
vasilii 2013/10/17 10:57:57 Blank line.
engedy 2013/10/17 15:13:47 Done.
87 86
88 void FileHostedPromptMemento::ReadValue( 87 void FileHostedPromptMemento::ReadValue(
89 const ReadValueCallback& callback) const { 88 const ReadValueCallback& callback) const {
90 base::FilePath path = GetMementoFilePath(); 89 base::FilePath path = GetMementoFilePath();
91 content::BrowserThread::PostTaskAndReplyWithResult( 90 content::BrowserThread::PostTaskAndReplyWithResult(
92 content::BrowserThread::FILE, 91 content::BrowserThread::FILE,
93 FROM_HERE, 92 FROM_HERE,
94 base::Bind(&ReadValueOnFileThread, path), 93 base::Bind(&ReadValueOnFileThread, path),
95 callback); 94 callback);
96 } 95 }
(...skipping 17 matching lines...) Expand all
114 const base::FilePath& memento_file_path, 113 const base::FilePath& memento_file_path,
115 const std::string& value) { 114 const std::string& value) {
116 int retval = 115 int retval =
117 file_util::WriteFile(memento_file_path, value.c_str(), value.size()); 116 file_util::WriteFile(memento_file_path, value.c_str(), value.size());
118 DCHECK_EQ(retval, (int)value.size()); 117 DCHECK_EQ(retval, (int)value.size());
119 } 118 }
120 119
121 base::FilePath FileHostedPromptMemento::GetMementoFilePath() const { 120 base::FilePath FileHostedPromptMemento::GetMementoFilePath() const {
122 return profile_->GetPath().Append(chrome::kResetPromptMementoFilename); 121 return profile_->GetPath().Append(chrome::kResetPromptMementoFilename);
123 } 122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698