OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/common/auto_start_linux.h" | 5 #include "chrome/common/auto_start_linux.h" |
6 | 6 |
7 #include "base/environment.h" | 7 #include "base/environment.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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 std::string autostart_file_contents = | 43 std::string autostart_file_contents = |
44 "[Desktop Entry]\n" | 44 "[Desktop Entry]\n" |
45 "Type=Application\n" | 45 "Type=Application\n" |
46 "Terminal=" + terminal + "\n" | 46 "Terminal=" + terminal + "\n" |
47 "Exec=" + command_line + "\n" | 47 "Exec=" + command_line + "\n" |
48 "Name=" + application_name + "\n"; | 48 "Name=" + application_name + "\n"; |
49 std::string::size_type content_length = autostart_file_contents.length(); | 49 std::string::size_type content_length = autostart_file_contents.length(); |
50 if (file_util::WriteFile(autostart_file, autostart_file_contents.c_str(), | 50 if (file_util::WriteFile(autostart_file, autostart_file_contents.c_str(), |
51 content_length) != | 51 content_length) != |
52 static_cast<int>(content_length)) { | 52 static_cast<int>(content_length)) { |
53 base::Delete(autostart_file, false); | 53 base::DeleteFile(autostart_file, false); |
54 return false; | 54 return false; |
55 } | 55 } |
56 return true; | 56 return true; |
57 } | 57 } |
58 | 58 |
59 bool AutoStart::Remove(const std::string& autostart_filename) { | 59 bool AutoStart::Remove(const std::string& autostart_filename) { |
60 scoped_ptr<base::Environment> environment(base::Environment::Create()); | 60 scoped_ptr<base::Environment> environment(base::Environment::Create()); |
61 base::FilePath autostart_directory = GetAutostartDirectory(environment.get()); | 61 base::FilePath autostart_directory = GetAutostartDirectory(environment.get()); |
62 base::FilePath autostart_file = | 62 base::FilePath autostart_file = |
63 autostart_directory.Append(autostart_filename); | 63 autostart_directory.Append(autostart_filename); |
64 return base::Delete(autostart_file, false); | 64 return base::DeleteFile(autostart_file, false); |
65 } | 65 } |
66 | 66 |
67 bool AutoStart::GetAutostartFileContents( | 67 bool AutoStart::GetAutostartFileContents( |
68 const std::string& autostart_filename, std::string* contents) { | 68 const std::string& autostart_filename, std::string* contents) { |
69 scoped_ptr<base::Environment> environment(base::Environment::Create()); | 69 scoped_ptr<base::Environment> environment(base::Environment::Create()); |
70 base::FilePath autostart_directory = GetAutostartDirectory(environment.get()); | 70 base::FilePath autostart_directory = GetAutostartDirectory(environment.get()); |
71 base::FilePath autostart_file = | 71 base::FilePath autostart_file = |
72 autostart_directory.Append(autostart_filename); | 72 autostart_directory.Append(autostart_filename); |
73 return file_util::ReadFileToString(autostart_file, contents); | 73 return file_util::ReadFileToString(autostart_file, contents); |
74 } | 74 } |
75 | 75 |
76 bool AutoStart::GetAutostartFileValue(const std::string& autostart_filename, | 76 bool AutoStart::GetAutostartFileValue(const std::string& autostart_filename, |
77 const std::string& value_name, | 77 const std::string& value_name, |
78 std::string* value) { | 78 std::string* value) { |
79 std::string contents; | 79 std::string contents; |
80 if (!GetAutostartFileContents(autostart_filename, &contents)) | 80 if (!GetAutostartFileContents(autostart_filename, &contents)) |
81 return false; | 81 return false; |
82 base::StringTokenizer tokenizer(contents, "\n"); | 82 base::StringTokenizer tokenizer(contents, "\n"); |
83 std::string token = value_name + "="; | 83 std::string token = value_name + "="; |
84 while (tokenizer.GetNext()) { | 84 while (tokenizer.GetNext()) { |
85 if (tokenizer.token().substr(0, token.length()) == token) { | 85 if (tokenizer.token().substr(0, token.length()) == token) { |
86 *value = tokenizer.token().substr(token.length()); | 86 *value = tokenizer.token().substr(token.length()); |
87 return true; | 87 return true; |
88 } | 88 } |
89 } | 89 } |
90 return false; | 90 return false; |
91 } | 91 } |
OLD | NEW |