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

Unified Diff: extensions/common/user_script.cc

Issue 495853002: Atomic UserScript ID generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/common/user_script.h ('k') | extensions/renderer/user_script_injector.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/common/user_script.cc
diff --git a/extensions/common/user_script.cc b/extensions/common/user_script.cc
index 2e705ce86fc6e8dff6a9cfc4db541b9037fa72a0..193a1139d508237c821099ab9de3b52c993c5b72 100644
--- a/extensions/common/user_script.cc
+++ b/extensions/common/user_script.cc
@@ -4,6 +4,7 @@
#include "extensions/common/user_script.h"
+#include "base/atomic_sequence_num.h"
#include "base/command_line.h"
#include "base/pickle.h"
#include "base/strings/string_util.h"
@@ -11,6 +12,10 @@
namespace {
+// This cannot be a plain int or int64 because we need to generate unique IDs
+// from multiple threads.
+base::StaticAtomicSequenceNumber g_user_script_id_generator;
+
bool UrlMatchesGlobs(const std::vector<std::string>* globs,
const GURL& url) {
for (std::vector<std::string>::const_iterator glob = globs->begin();
@@ -38,6 +43,12 @@ enum {
// static
const char UserScript::kFileExtension[] = ".user.js";
+
+// static
+int UserScript::GenerateUserScriptID() {
+ return g_user_script_id_generator.GetNext();
+}
+
bool UserScript::IsURLUserScript(const GURL& url,
const std::string& mime_type) {
return EndsWith(url.ExtractFileName(), kFileExtension, false) &&
@@ -128,7 +139,7 @@ void UserScript::Pickle(::Pickle* pickle) const {
// Write the simple types to the pickle.
pickle->WriteInt(run_location());
pickle->WriteString(extension_id());
- pickle->WriteInt64(user_script_id_);
+ pickle->WriteInt(user_script_id_);
pickle->WriteBool(emulate_greasemonkey());
pickle->WriteBool(match_all_frames());
pickle->WriteBool(match_about_blank());
@@ -178,7 +189,7 @@ void UserScript::Unpickle(const ::Pickle& pickle, PickleIterator* iter) {
run_location_ = static_cast<RunLocation>(run_location);
CHECK(pickle.ReadString(iter, &extension_id_));
- CHECK(pickle.ReadInt64(iter, &user_script_id_));
+ CHECK(pickle.ReadInt(iter, &user_script_id_));
CHECK(pickle.ReadBool(iter, &emulate_greasemonkey_));
CHECK(pickle.ReadBool(iter, &match_all_frames_));
CHECK(pickle.ReadBool(iter, &match_about_blank_));
« no previous file with comments | « extensions/common/user_script.h ('k') | extensions/renderer/user_script_injector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698