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

Side by Side Diff: chrome/browser/shell_integration_linux.cc

Issue 12386077: shell_integration_linux: Follow the XDG Base Directory Specification. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Swap /usr/share and /usr/local/share to match the spec. Created 7 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/shell_integration_unittest.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) 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/browser/shell_integration_linux.h" 5 #include "chrome/browser/shell_integration_linux.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <glib.h> 8 #include <glib.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 return "chromium-browser.desktop"; 456 return "chromium-browser.desktop";
457 #endif 457 #endif
458 } 458 }
459 459
460 bool GetDesktopShortcutTemplate(base::Environment* env, 460 bool GetDesktopShortcutTemplate(base::Environment* env,
461 std::string* output) { 461 std::string* output) {
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
463 463
464 std::vector<base::FilePath> search_paths; 464 std::vector<base::FilePath> search_paths;
465 465
466 // Search paths as specified in the XDG Base Directory Specification.
467 // http://standards.freedesktop.org/basedir-spec/latest/
466 std::string xdg_data_home; 468 std::string xdg_data_home;
469 std::string home;
467 if (env->GetVar("XDG_DATA_HOME", &xdg_data_home) && 470 if (env->GetVar("XDG_DATA_HOME", &xdg_data_home) &&
468 !xdg_data_home.empty()) { 471 !xdg_data_home.empty()) {
469 search_paths.push_back(base::FilePath(xdg_data_home)); 472 search_paths.push_back(base::FilePath(xdg_data_home));
473 } else if (env->GetVar("HOME", &home) && !home.empty()) {
474 search_paths.push_back(base::FilePath(home).Append(".local").Append(
475 "share"));
470 } 476 }
471 477
472 std::string xdg_data_dirs; 478 std::string xdg_data_dirs;
473 if (env->GetVar("XDG_DATA_DIRS", &xdg_data_dirs) && 479 if (env->GetVar("XDG_DATA_DIRS", &xdg_data_dirs) &&
474 !xdg_data_dirs.empty()) { 480 !xdg_data_dirs.empty()) {
475 base::StringTokenizer tokenizer(xdg_data_dirs, ":"); 481 base::StringTokenizer tokenizer(xdg_data_dirs, ":");
476 while (tokenizer.GetNext()) { 482 while (tokenizer.GetNext()) {
477 base::FilePath data_dir(tokenizer.token()); 483 base::FilePath data_dir(tokenizer.token());
478 search_paths.push_back(data_dir); 484 search_paths.push_back(data_dir);
479 search_paths.push_back(data_dir.Append("applications"));
480 } 485 }
486 } else {
487 search_paths.push_back(base::FilePath("/usr/local/share"));
488 search_paths.push_back(base::FilePath("/usr/share"));
481 } 489 }
482 490
483 // Add some fallback paths for systems which don't have XDG_DATA_DIRS or have
484 // it incomplete.
485 search_paths.push_back(base::FilePath("/usr/share/applications"));
486 search_paths.push_back(base::FilePath("/usr/local/share/applications"));
487
488 std::string template_filename(GetDesktopName(env)); 491 std::string template_filename(GetDesktopName(env));
489 for (std::vector<base::FilePath>::const_iterator i = search_paths.begin(); 492 for (std::vector<base::FilePath>::const_iterator i = search_paths.begin();
490 i != search_paths.end(); ++i) { 493 i != search_paths.end(); ++i) {
491 base::FilePath path = i->Append(template_filename); 494 base::FilePath path = i->Append("applications").Append(template_filename);
492 VLOG(1) << "Looking for desktop file template in " << path.value(); 495 VLOG(1) << "Looking for desktop file template in " << path.value();
493 if (file_util::PathExists(path)) { 496 if (file_util::PathExists(path)) {
494 VLOG(1) << "Found desktop file template at " << path.value(); 497 VLOG(1) << "Found desktop file template at " << path.value();
495 return file_util::ReadFileToString(path, output); 498 return file_util::ReadFileToString(path, output);
496 } 499 }
497 } 500 }
498 501
499 LOG(ERROR) << "Could not find desktop file template."; 502 LOG(ERROR) << "Could not find desktop file template.";
500 return false; 503 return false;
501 } 504 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 728
726 base::FilePath shortcut_filename = GetExtensionShortcutFilename( 729 base::FilePath shortcut_filename = GetExtensionShortcutFilename(
727 profile_path, extension_id); 730 profile_path, extension_id);
728 DCHECK(!shortcut_filename.empty()); 731 DCHECK(!shortcut_filename.empty());
729 732
730 DeleteShortcutOnDesktop(shortcut_filename); 733 DeleteShortcutOnDesktop(shortcut_filename);
731 DeleteShortcutInApplicationsMenu(shortcut_filename); 734 DeleteShortcutInApplicationsMenu(shortcut_filename);
732 } 735 }
733 736
734 } // namespace ShellIntegrationLinux 737 } // namespace ShellIntegrationLinux
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/shell_integration_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698