summaryrefslogtreecommitdiffstats
path: root/extensions/common/user_script.cc
diff options
context:
space:
mode:
authormarkdittmer@chromium.org <markdittmer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-22 20:04:42 +0000
committermarkdittmer@chromium.org <markdittmer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-22 20:06:40 +0000
commiteab3cc5f177b76a2c27b69d306bd22c05559ec40 (patch)
tree22988f015303e2c7332c7873a362a3a5c5706f54 /extensions/common/user_script.cc
parent997465401e352648212324e5f439bab49255fa91 (diff)
downloadchromium_src-eab3cc5f177b76a2c27b69d306bd22c05559ec40.zip
chromium_src-eab3cc5f177b76a2c27b69d306bd22c05559ec40.tar.gz
chromium_src-eab3cc5f177b76a2c27b69d306bd22c05559ec40.tar.bz2
Atomic UserScript ID generation
BUG=377978 Review URL: https://codereview.chromium.org/495853002 Cr-Commit-Position: refs/heads/master@{#291489} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291489 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/common/user_script.cc')
-rw-r--r--extensions/common/user_script.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/extensions/common/user_script.cc b/extensions/common/user_script.cc
index 2e705ce8..193a113 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_));