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

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: Rebased to ToT. 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.h"
7 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
8 #include "base/file_util.h" 9 #include "base/file_util.h"
9 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/prefs/scoped_user_pref_update.h" 15 #include "chrome/browser/prefs/scoped_user_pref_update.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_constants.h" 17 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 20
20 using base::DictionaryValue; 21 using base::DictionaryValue;
21 22
23
22 // AutomaticProfileResetter::PreferenceHostedPromptMemento ------------------- 24 // AutomaticProfileResetter::PreferenceHostedPromptMemento -------------------
23 25
24 PreferenceHostedPromptMemento::PreferenceHostedPromptMemento(Profile* profile) 26 PreferenceHostedPromptMemento::PreferenceHostedPromptMemento(Profile* profile)
25 : profile_(profile) {} 27 : profile_(profile) {}
28
26 PreferenceHostedPromptMemento::~PreferenceHostedPromptMemento() {} 29 PreferenceHostedPromptMemento::~PreferenceHostedPromptMemento() {}
27 30
28 std::string PreferenceHostedPromptMemento::ReadValue() const { 31 std::string PreferenceHostedPromptMemento::ReadValue() const {
29 PrefService* prefs = profile_->GetPrefs(); 32 PrefService* prefs = profile_->GetPrefs();
30 DCHECK(prefs); 33 DCHECK(prefs);
31 return prefs->GetString(prefs::kProfileResetPromptMemento); 34 return prefs->GetString(prefs::kProfileResetPromptMemento);
32 } 35 }
33 36
34 void PreferenceHostedPromptMemento::StoreValue(const std::string& value) { 37 void PreferenceHostedPromptMemento::StoreValue(const std::string& value) {
35 PrefService* prefs = profile_->GetPrefs(); 38 PrefService* prefs = profile_->GetPrefs();
36 DCHECK(prefs); 39 DCHECK(prefs);
37 prefs->SetString(prefs::kProfileResetPromptMemento, value); 40 prefs->SetString(prefs::kProfileResetPromptMemento, value);
38 } 41 }
39 42
43
40 // AutomaticProfileResetter::LocalStateHostedPromptMemento ------------------- 44 // AutomaticProfileResetter::LocalStateHostedPromptMemento -------------------
41 45
42 LocalStateHostedPromptMemento::LocalStateHostedPromptMemento(Profile* profile) 46 LocalStateHostedPromptMemento::LocalStateHostedPromptMemento(Profile* profile)
43 : profile_(profile) {} 47 : profile_(profile) {}
48
44 LocalStateHostedPromptMemento::~LocalStateHostedPromptMemento() {} 49 LocalStateHostedPromptMemento::~LocalStateHostedPromptMemento() {}
45 50
46 std::string LocalStateHostedPromptMemento::ReadValue() const { 51 std::string LocalStateHostedPromptMemento::ReadValue() const {
47 PrefService* local_state = g_browser_process->local_state(); 52 PrefService* local_state = g_browser_process->local_state();
48 DCHECK(local_state); 53 DCHECK(local_state);
49 54
50 const DictionaryValue* prompt_shown_dict = 55 const DictionaryValue* prompt_shown_dict =
51 local_state->GetDictionary(prefs::kProfileResetPromptMemento); 56 local_state->GetDictionary(prefs::kProfileResetPromptMemento);
52 std::string profile_key = GetProfileKey(); 57 std::string profile_key = GetProfileKey();
53 if (!prompt_shown_dict || profile_key.empty()) { 58 if (!prompt_shown_dict || profile_key.empty()) {
54 NOTREACHED(); 59 NOTREACHED();
55 return ""; 60 return std::string();
56 } 61 }
57 std::string value; 62 std::string value;
58 return prompt_shown_dict->GetStringWithoutPathExpansion(profile_key, &value) 63 return prompt_shown_dict->GetStringWithoutPathExpansion(profile_key, &value) ?
59 ? value 64 value : std::string();
60 : "";
61 } 65 }
62 66
63 void LocalStateHostedPromptMemento::StoreValue(const std::string& value) { 67 void LocalStateHostedPromptMemento::StoreValue(const std::string& value) {
64 PrefService* local_state = g_browser_process->local_state(); 68 PrefService* local_state = g_browser_process->local_state();
65 DCHECK(local_state); 69 DCHECK(local_state);
66 70
67 DictionaryPrefUpdate prompt_shown_dict_update( 71 DictionaryPrefUpdate prompt_shown_dict_update(
68 local_state, prefs::kProfileResetPromptMemento); 72 local_state, prefs::kProfileResetPromptMemento);
69 std::string profile_key = GetProfileKey(); 73 std::string profile_key = GetProfileKey();
70 if (profile_key.empty()) { 74 if (profile_key.empty()) {
71 NOTREACHED(); 75 NOTREACHED();
72 return; 76 return;
73 } 77 }
74 prompt_shown_dict_update.Get()->SetStringWithoutPathExpansion(profile_key, 78 prompt_shown_dict_update.Get()->SetStringWithoutPathExpansion(profile_key,
75 value); 79 value);
76 } 80 }
77 81
78 std::string LocalStateHostedPromptMemento::GetProfileKey() const { 82 std::string LocalStateHostedPromptMemento::GetProfileKey() const {
79 return profile_->GetPath().BaseName().MaybeAsASCII(); 83 return profile_->GetPath().BaseName().MaybeAsASCII();
80 } 84 }
81 85
86
82 // AutomaticProfileResetter::FileHostedPromptMemento ------------------------- 87 // AutomaticProfileResetter::FileHostedPromptMemento -------------------------
83 88
84 FileHostedPromptMemento::FileHostedPromptMemento(Profile* profile) 89 FileHostedPromptMemento::FileHostedPromptMemento(Profile* profile)
85 : profile_(profile) {} 90 : profile_(profile) {}
91
86 FileHostedPromptMemento::~FileHostedPromptMemento() {} 92 FileHostedPromptMemento::~FileHostedPromptMemento() {}
87 93
88 void FileHostedPromptMemento::ReadValue( 94 void FileHostedPromptMemento::ReadValue(
89 const ReadValueCallback& callback) const { 95 const ReadValueCallback& callback) const {
90 base::FilePath path = GetMementoFilePath(); 96 base::FilePath path = GetMementoFilePath();
91 content::BrowserThread::PostTaskAndReplyWithResult( 97 content::BrowserThread::PostTaskAndReplyWithResult(
92 content::BrowserThread::FILE, 98 content::BrowserThread::FILE,
93 FROM_HERE, 99 FROM_HERE,
94 base::Bind(&ReadValueOnFileThread, path), 100 base::Bind(&ReadValueOnFileThread, path),
95 callback); 101 callback);
(...skipping 18 matching lines...) Expand all
114 const base::FilePath& memento_file_path, 120 const base::FilePath& memento_file_path,
115 const std::string& value) { 121 const std::string& value) {
116 int retval = 122 int retval =
117 file_util::WriteFile(memento_file_path, value.c_str(), value.size()); 123 file_util::WriteFile(memento_file_path, value.c_str(), value.size());
118 DCHECK_EQ(retval, (int)value.size()); 124 DCHECK_EQ(retval, (int)value.size());
119 } 125 }
120 126
121 base::FilePath FileHostedPromptMemento::GetMementoFilePath() const { 127 base::FilePath FileHostedPromptMemento::GetMementoFilePath() const {
122 return profile_->GetPath().Append(chrome::kResetPromptMementoFilename); 128 return profile_->GetPath().Append(chrome::kResetPromptMementoFilename);
123 } 129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698