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

Side by Side Diff: chromeos/dbus/session_manager_client.cc

Issue 2608943002: Use TaskScheduler instead of WorkerPool in session_manager_client.cc. (Closed)
Patch Set: format Created 3 years, 11 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 | no next file » | 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 "chromeos/dbus/session_manager_client.h" 5 #include "chromeos/dbus/session_manager_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/task_runner_util.h" 21 #include "base/task_scheduler/post_task.h"
22 #include "base/threading/worker_pool.h"
23 #include "chromeos/chromeos_paths.h" 22 #include "chromeos/chromeos_paths.h"
24 #include "chromeos/cryptohome/cryptohome_parameters.h" 23 #include "chromeos/cryptohome/cryptohome_parameters.h"
25 #include "chromeos/dbus/blocking_method_caller.h" 24 #include "chromeos/dbus/blocking_method_caller.h"
26 #include "chromeos/dbus/cryptohome_client.h" 25 #include "chromeos/dbus/cryptohome_client.h"
27 #include "components/policy/proto/device_management_backend.pb.h" 26 #include "components/policy/proto/device_management_backend.pb.h"
28 #include "crypto/sha2.h" 27 #include "crypto/sha2.h"
29 #include "dbus/bus.h" 28 #include "dbus/bus.h"
30 #include "dbus/message.h" 29 #include "dbus/message.h"
31 #include "dbus/object_path.h" 30 #include "dbus/object_path.h"
32 #include "dbus/object_proxy.h" 31 #include "dbus/object_proxy.h"
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 void RetrieveActiveSessions(const ActiveSessionsCallback& callback) override { 814 void RetrieveActiveSessions(const ActiveSessionsCallback& callback) override {
816 } 815 }
817 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { 816 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override {
818 base::FilePath owner_key_path; 817 base::FilePath owner_key_path;
819 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { 818 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) {
820 callback.Run(""); 819 callback.Run("");
821 return; 820 return;
822 } 821 }
823 base::FilePath device_policy_path = 822 base::FilePath device_policy_path =
824 owner_key_path.DirName().AppendASCII("stub_device_policy"); 823 owner_key_path.DirName().AppendASCII("stub_device_policy");
825 base::PostTaskAndReplyWithResult( 824 base::PostTaskWithTraitsAndReplyWithResult(
826 base::WorkerPool::GetTaskRunner(false).get(), 825 FROM_HERE, base::TaskTraits()
827 FROM_HERE, 826 .WithShutdownBehavior(
828 base::Bind(&GetFileContent, device_policy_path), 827 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
829 callback); 828 .MayBlock(),
829 base::Bind(&GetFileContent, device_policy_path), callback);
830 } 830 }
831 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, 831 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id,
832 const RetrievePolicyCallback& callback) override { 832 const RetrievePolicyCallback& callback) override {
833 base::PostTaskAndReplyWithResult( 833 base::PostTaskWithTraitsAndReplyWithResult(
834 base::WorkerPool::GetTaskRunner(false).get(), FROM_HERE, 834 FROM_HERE, base::TaskTraits()
835 .WithShutdownBehavior(
836 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
837 .MayBlock(),
835 base::Bind(&GetFileContent, 838 base::Bind(&GetFileContent,
836 GetUserFilePath(cryptohome_id, "stub_policy")), 839 GetUserFilePath(cryptohome_id, "stub_policy")),
837 callback); 840 callback);
838 } 841 }
839 std::string BlockingRetrievePolicyForUser( 842 std::string BlockingRetrievePolicyForUser(
840 const cryptohome::Identification& cryptohome_id) override { 843 const cryptohome::Identification& cryptohome_id) override {
841 return GetFileContent(GetUserFilePath(cryptohome_id, "stub_policy")); 844 return GetFileContent(GetUserFilePath(cryptohome_id, "stub_policy"));
842 } 845 }
843 void RetrieveDeviceLocalAccountPolicy( 846 void RetrieveDeviceLocalAccountPolicy(
844 const std::string& account_id, 847 const std::string& account_id,
845 const RetrievePolicyCallback& callback) override { 848 const RetrievePolicyCallback& callback) override {
846 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id), 849 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id),
847 callback); 850 callback);
848 } 851 }
849 void StoreDevicePolicy(const std::string& policy_blob, 852 void StoreDevicePolicy(const std::string& policy_blob,
850 const StorePolicyCallback& callback) override { 853 const StorePolicyCallback& callback) override {
851 enterprise_management::PolicyFetchResponse response; 854 enterprise_management::PolicyFetchResponse response;
852 base::FilePath owner_key_path; 855 base::FilePath owner_key_path;
853 if (!response.ParseFromString(policy_blob) || 856 if (!response.ParseFromString(policy_blob) ||
854 !PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { 857 !PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) {
855 callback.Run(false); 858 callback.Run(false);
856 return; 859 return;
857 } 860 }
858 861
859 if (response.has_new_public_key()) { 862 if (response.has_new_public_key()) {
860 base::WorkerPool::PostTask( 863 base::PostTaskWithTraits(
861 FROM_HERE, 864 FROM_HERE, base::TaskTraits()
862 base::Bind(&StoreFile, owner_key_path, response.new_public_key()), 865 .WithShutdownBehavior(
863 false); 866 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
867 .MayBlock(),
868 base::Bind(&StoreFile, owner_key_path, response.new_public_key()));
864 } 869 }
865 870
866 // Chrome will attempt to retrieve the device policy right after storing 871 // Chrome will attempt to retrieve the device policy right after storing
867 // during enrollment, so make sure it's written before signaling 872 // during enrollment, so make sure it's written before signaling
868 // completion. 873 // completion.
869 // Note also that the owner key will be written before the device policy, 874 // Note also that the owner key will be written before the device policy,
870 // if it was present in the blob. 875 // if it was present in the blob.
871 base::FilePath device_policy_path = 876 base::FilePath device_policy_path =
872 owner_key_path.DirName().AppendASCII("stub_device_policy"); 877 owner_key_path.DirName().AppendASCII("stub_device_policy");
873 base::WorkerPool::PostTaskAndReply( 878 base::PostTaskWithTraitsAndReply(
874 FROM_HERE, 879 FROM_HERE, base::TaskTraits()
880 .WithShutdownBehavior(
881 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
882 .MayBlock(),
875 base::Bind(&StoreFile, device_policy_path, policy_blob), 883 base::Bind(&StoreFile, device_policy_path, policy_blob),
876 base::Bind(callback, true), 884 base::Bind(callback, true));
877 false);
878 } 885 }
879 void StorePolicyForUser(const cryptohome::Identification& cryptohome_id, 886 void StorePolicyForUser(const cryptohome::Identification& cryptohome_id,
880 const std::string& policy_blob, 887 const std::string& policy_blob,
881 const StorePolicyCallback& callback) override { 888 const StorePolicyCallback& callback) override {
882 // The session manager writes the user policy key to a well-known 889 // The session manager writes the user policy key to a well-known
883 // location. Do the same with the stub impl, so that user policy works and 890 // location. Do the same with the stub impl, so that user policy works and
884 // can be tested on desktop builds. 891 // can be tested on desktop builds.
885 enterprise_management::PolicyFetchResponse response; 892 enterprise_management::PolicyFetchResponse response;
886 if (!response.ParseFromString(policy_blob)) { 893 if (!response.ParseFromString(policy_blob)) {
887 callback.Run(false); 894 callback.Run(false);
888 return; 895 return;
889 } 896 }
890 897
891 if (response.has_new_public_key()) { 898 if (response.has_new_public_key()) {
892 base::FilePath key_path = GetUserFilePath(cryptohome_id, "policy.pub"); 899 base::FilePath key_path = GetUserFilePath(cryptohome_id, "policy.pub");
893 base::WorkerPool::PostTask( 900 base::PostTaskWithTraits(
894 FROM_HERE, 901 FROM_HERE, base::TaskTraits()
895 base::Bind(&StoreFile, key_path, response.new_public_key()), 902 .WithShutdownBehavior(
896 false); 903 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
904 .MayBlock(),
905 base::Bind(&StoreFile, key_path, response.new_public_key()));
897 } 906 }
898 907
899 // This file isn't read directly by Chrome, but is used by this class to 908 // This file isn't read directly by Chrome, but is used by this class to
900 // reload the user policy across restarts. 909 // reload the user policy across restarts.
901 base::FilePath stub_policy_path = 910 base::FilePath stub_policy_path =
902 GetUserFilePath(cryptohome_id, "stub_policy"); 911 GetUserFilePath(cryptohome_id, "stub_policy");
903 base::WorkerPool::PostTaskAndReply( 912 base::PostTaskWithTraitsAndReply(
904 FROM_HERE, 913 FROM_HERE, base::TaskTraits()
914 .WithShutdownBehavior(
915 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
916 .MayBlock(),
905 base::Bind(&StoreFile, stub_policy_path, policy_blob), 917 base::Bind(&StoreFile, stub_policy_path, policy_blob),
906 base::Bind(callback, true), 918 base::Bind(callback, true));
907 false);
908 } 919 }
909 void StoreDeviceLocalAccountPolicy( 920 void StoreDeviceLocalAccountPolicy(
910 const std::string& account_id, 921 const std::string& account_id,
911 const std::string& policy_blob, 922 const std::string& policy_blob,
912 const StorePolicyCallback& callback) override { 923 const StorePolicyCallback& callback) override {
913 StorePolicyForUser(cryptohome::Identification::FromString(account_id), 924 StorePolicyForUser(cryptohome::Identification::FromString(account_id),
914 policy_blob, callback); 925 policy_blob, callback);
915 } 926 }
916 void SetFlagsForUser(const cryptohome::Identification& cryptohome_id, 927 void SetFlagsForUser(const cryptohome::Identification& cryptohome_id,
917 const std::vector<std::string>& flags) override {} 928 const std::vector<std::string>& flags) override {}
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 983
973 SessionManagerClient* SessionManagerClient::Create( 984 SessionManagerClient* SessionManagerClient::Create(
974 DBusClientImplementationType type) { 985 DBusClientImplementationType type) {
975 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 986 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
976 return new SessionManagerClientImpl(); 987 return new SessionManagerClientImpl();
977 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); 988 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type);
978 return new SessionManagerClientStubImpl(); 989 return new SessionManagerClientStubImpl();
979 } 990 }
980 991
981 } // namespace chromeos 992 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698